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

Bad idea. Generic methods both set and return ...
#!/usr/bin/perl -- use strict; use warnings; use URI; my $base = 'http://foobert.org/dir/odir'; my $file = 'foo.html'; my $uri = URI->new($base); local $\=$/; print $uri->path_segments( $uri->path_segments, $file ); print $uri; print $uri->host('I-RTFM.org'); print $uri; __END__ dirodir http://foobert.org/dir/odir/foo.html foobert.org http://I-RTFM.org/dir/odir/foo.html

Replies are listed 'Best First'.
Re^2: URI plus File::Spec::Unix -- good idea or bad?
by mreece (Friar) on Aug 25, 2006 at 16:35 UTC
    $uri->path_segments is interesting and useful, but it doesn't solve the "behave the same whether $base ends with a slash or not" problem.

    change the code to my $base = 'http://foobert.org/dir/odir/'; and you get http://foobert.org/dir/odir//foo.html, with two slashes!

      however, this will do it :)
      print $uri->path_segments( grep { $_ } $uri->path_segments, $file );
      uses grep to filter out the empty strings returned by path_segments.

      updated: fixed typo