in reply to URI plus File::Spec::Unix -- good idea or bad?

URLs are the same everywhere you go, so you don't need the localization magic of File::Spec to figure out how to put them together. Just use the forward slash (/) to join the path elements. It's so trivial I guess URI doesn't see fit to wrap it in a method name. :)

So, in your example, if $uri->path ends in a slash, just concatenate the foo.html. If the $uri->path doesn't end in a slash, make it end in a slash, then add the foo.html. That's just what File::Spec::Unix->catfile is doing, although you're not really supposed to be peeking down there. :) If that's all your using that module for, it's probably not worth it to even compile it. :)

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

Replies are listed 'Best First'.
Re^2: URI plus File::Spec::Unix -- good idea or bad?
by mreece (Friar) on Aug 24, 2006 at 21:43 UTC
    of course, but my goal is to avoid the "if the $uri->path doesn't end in a slash do something different" part, if possible.
    $uri->path( $uri->path =~ m{/$} ? $uri->path . 'index.html' : $uri->pa +th . '/index.html')
    and similar seems more clumsy.

    what i actually end up with is typically more like $base .= '/' unless $base =~ m{/$};, but i'm looking for something smarter, because i hate repeating these things and the problem is so easily solved (use File::Spec) with other file paths outside of URI context.

    as for localization, that's why i used File::Spec::Unix explicitly, because you are correct, i don't need localization magic.
      Slightly less clumsy?
      $uri->path( $uri->path .( $uri->path =~ m{/$} ? '' : '/' ) .'index.html' );