From: Jonathan Bromley on
This is probably a painfully basic question, sorry.

We have [file split] and [file join] for all the
right reasons. But what should I do if I want the
inverse operation of [file split], i.e. reassemble
a list of path components into a platform-appropriate
pathname?

Given
set components [file split $original_path]
here are some attempts, none of which really satisfies me:

set newpath [eval file join $components]
# I don't like eval very much....

set newpath [join $components [file separator]]
# is this really safe? Duplicated separators???

set newpath {}
foreach piece $components {
set newpath [file join $newpath $piece]
}
# looks clumsy, probably quite slow

set newpath [file join {*}$components]
# probably best, but usually I'm stuck with Tcl 8.4

Is there something simple and obvious I've missed?

Thanks in advance
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley(a)MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
From: Andreas Leitgeb on
Jonathan Bromley <jonathan.bromley(a)MYCOMPANY.com> wrote:
> Given
> set components [file split $original_path]
> here are some attempts, none of which really satisfies me:
>
> set newpath [eval file join $components]
> # I don't like eval very much....
>
> set newpath [file join {*}$components]
> # probably best, but usually I'm stuck with Tcl 8.4

I'd most suggest trying to get unstuck and upgrade to 8.5
but leaving that aside, eval ist the way. You can, however,
treat the arguments to eval such, that it will be safe and
not all that slow:

set newpath [eval [linsert $components 0 file join]]
# yes, sucks, too, but that's why {*} was at long last added to 8.5

From: Jonathan Bromley on
On 11 Sep 2009 10:09:48 GMT, Andreas Leitgeb wrote:

>I'd most suggest trying to get unstuck and upgrade to 8.5

When Tcl is embedded in a commercial tool, I don't have
that luxury :-(

>treat the arguments to eval such, that it will be safe and
>not all that slow:
>
>set newpath [eval [linsert $components 0 file join]]

ah, yes, that's nicer. Every Script Is A List.

Thanks.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley(a)MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
From: Don Porter on
Jonathan Bromley wrote:
> ah, yes, that's nicer. Every Script Is A List.

Careful. You got that backwards.
From: Uwe Klein on
Jonathan Bromley wrote:
> On 11 Sep 2009 10:09:48 GMT, Andreas Leitgeb wrote:
>
>
>>I'd most suggest trying to get unstuck and upgrade to 8.5
>
>
> When Tcl is embedded in a commercial tool, I don't have
> that luxury :-(
>
>
>>treat the arguments to eval such, that it will be safe and
>>not all that slow:
>>
>>set newpath [eval [linsert $components 0 file join]]
>
>
> ah, yes, that's nicer. Every Script Is A List.

you can have it faster even:

set newpath [if true [linsert $components 0 file join]]]

uwe