polettix has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to get rid of references to parent directory in a path, but it seems that File::Spec doesn't help me much:
Is there any module that addresses this problem? TIA,#!/usr/bin/perl use strict; use warnings; use File::Spec; my $somepath = "/var/log/../../home/poletti/../../etc/passwd"; print "starting path: [$somepath]\n"; print "wanted path: [/etc/passwd]"; print "canonpath: [", File::Spec->canonpath($somepath), "]\n"; print "rel2abs: [", File::Spec->rel2abs($somepath), "]\n"; print "abs2rel: [", File::Spec->rel2abs($somepath, "/"), "]\n"; my @portions = File::Spec->splitpath($somepath); print "splitpath + catpath: [", File::Spec->catpath(@portions), "]\n"; __END__ __output__ starting path: [/var/log/../../home/poletti/../../etc/passwd] wanted path: [/etc/passwd] canonpath: [/var/log/../../home/poletti/../../etc/passwd] rel2abs: [/var/log/../../home/poletti/../../etc/passwd] abs2rel: [/var/log/../../home/poletti/../../etc/passwd] splitpath + catpath: [/var/log/../../home/poletti/../../etc/passwd]
Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")
Don't fool yourself.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cleaning up a path
by ikegami (Patriarch) on Apr 13, 2005 at 17:29 UTC | |
|
Re: Cleaning up a path
by tlm (Prior) on Apr 13, 2005 at 17:26 UTC | |
|
Re: Cleaning up a path
by Roy Johnson (Monsignor) on Apr 13, 2005 at 19:54 UTC | |
|
Re: Cleaning up a path
by derby (Abbot) on Apr 13, 2005 at 17:38 UTC | |
by Roy Johnson (Monsignor) on Apr 13, 2005 at 18:29 UTC | |
by ikegami (Patriarch) on Apr 13, 2005 at 18:39 UTC | |
by ikegami (Patriarch) on Apr 13, 2005 at 17:52 UTC | |
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 | |
|
Re: Cleaning up a path
by polettix (Vicar) on Nov 18, 2006 at 12:20 UTC |