develooper Front page | perl.libwww | Postings from March 2003


Thread Next
Sean M. Burke
March 12, 2003 22:56
Message ID:
One of the timid woodland creatures that read my /Perl and LWP/ book came 
and asked me a question the other day.  It's an interesting question with a 
somewhat surprising answer, so I'll copy it here:

At 11:37 AM 2003-03-12 -0500, [some guy] wrote:
>Sorry to bug you, but I have a quick question I cant find the answer to.
>When using URI::URL (or normal URI) and breaking down a url to grab 
>$url->path_segments(); is the first one that is returned always blank or 
>is it just me? and if this is correct, why is it always blank? I find 
>myself having to grab $blah[1] to get the first actual segment.

I've been wondering about this for ages.  But just now I thought of the 
answer (or at least an answer): relative URL objects!  They don't have to 
start with a slash, so their $blah[0] might have something in it.


% perl -d  -e 1
Loading DB routines from version 1.19
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(-e:1):   -1
   DB<1> use URI

   DB<2> $x = URI->new('stuff/things')

   DB<3> x $x->canonical->as_string
0  'stuff/things'
   DB<4> x $x->path_segments
0  'stuff'
1  'things'

Sean M. Burke

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About