in reply to Cleaning up a path
Well, if you're not worried about portablity:
!/usr/bin/perl use strict; use warnings; my $somepath = "/var/log/../../home/poletti/../../etc/passwd"; my( @true ); foreach( split( /\//, $somepath ) ) { $_ eq ".." ? pop( @true ) : push( @true, $_ ); } print join( '/', @true ), "\n";
Let the golf begin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(golf): Cleaning up a path
by Roy Johnson (Monsignor) on Apr 13, 2005 at 18:29 UTC | |
by ikegami (Patriarch) on Apr 13, 2005 at 18:39 UTC | |
|
Re^2: Cleaning up a path
by ikegami (Patriarch) on Apr 13, 2005 at 17:52 UTC | |
|
Re^2: Cleaning up a path
by polettix (Vicar) on Apr 13, 2005 at 18:00 UTC | |
by ikegami (Patriarch) on Apr 13, 2005 at 18:03 UTC | |
by polettix (Vicar) on Apr 13, 2005 at 18:14 UTC | |
by ikegami (Patriarch) on Apr 13, 2005 at 18:28 UTC |