in reply to Absolute pathnames from relative?

It seems that you want a module that does something like this:
my $fn= File::Spec->rel2abs("../bin/fnurgle","/usr/local/bin"); print "Before: $fn\n"; for (File::Spec->splitdir($fn)) { if ($_ ne "..") { push @arr, $_ } else { pop @arr } } print "After: ",File::Spec->catdir(@arr),"\n";
but I couldn't find it either. Of course, we could transform the for loop into a map, go on a quest, and golf it!

It should work perfectly the first time! - toma

Replies are listed 'Best First'.
Re^2: Absolute pathnames from relative?
by PodMaster (Abbot) on Jun 09, 2004 at 20:38 UTC
    This could be a good addition to File::Spec
    sub File::Spec::un_upwards { my($self, $foo) = @_; $foo = $self->canonpath( $foo ); my $updir = $self->updir(); return $foo if -1 == index $foo, $updir; my( $volume, $directories, $file ) = $self->splitpath($foo); my @dar; foreach($self->splitdir( $directories )){ if( $_ eq $updir ){ if(@dar){# in case the path is relative, ie ../fo/bar/base pop @dar; } else { push @dar, $_; } } else { push @dar, $_; } } return $self->catpath( $volume, $self->catdir( @dar ), $file ); }

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.