Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to get a true canonical path

by valdez (Monsignor)
on Jun 09, 2004 at 16:01 UTC ( [id://362785]=note: print w/replies, xml ) Need Help??


in reply to How to get a true canonical path

I use URI:

#!/usr/bin/perl use strict; use warnings; use URI; my $base_uri = URI->new( '/home/httpd/project/' ); while (my $path = <DATA>) { chomp($path); my $absolute = URI->new_abs( $path, $base_uri ); printf "%s + %s: %s\n", $base_uri->canonical, $path, $absolute->cano +nical; } __DATA__ ../another/ subdir/ ../../../etc/very/dangerous ../project/
update: it seems that I didn't understand the question, sorry.
update2: However, it seems that URI::file does understand OS differences and does what you want:
use URI::file; my $base_uri = URI::file->new( URI::file->cwd ); while (my $path = <DATA>) { chomp($path); my $absolute = URI::file->new_abs( $path, $base_uri ); printf "%s + %s: %s\n", $base_uri->canonical, $path, $absolute->file +; } __DATA__ ../another/ subdir/ ../../../some/other/place ../project/

HTH, Valerio

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://362785]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-29 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found