Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

petdance (2468)

AOL IM: petdance (Add Buddy, Send Message)
Yahoo! ID: petdance (Add User, Send Message)

I'm Andy Lester, and I like to test stuff. I also write for the Perl Journal, and do tech edits on books. Sometimes I write code, too.

Journal of petdance (2468)

Tuesday August 06, 2002
02:45 PM

Misusing URI for filename tweaking

[ #6941 ]
(Which is not the same as misusing Uri)

I just realized I could use URI to make full pathnames into relative pathnames:

my $dispname = URI->new("file://$filename")->rel("file://$startpath");

This way, if






That construct, modulo the "file://", is stolen from Sean Burke's excellent Perl & LWP, page 56.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • File::Spec has an abs2rel() method to do that, and should handle OS-specific path separators as well.

    Of course, that doesn't have the fun of misuse.
    • ARGH. I can't tell you how many times I went over File::Spec in Perl In A Nutshell looking for something like that. I wonder if it's missing, and I should have stuck to the man pages.

      Thanks for pointing it out.