Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Split Help

by almut (Canon)
on May 11, 2010 at 07:55 UTC ( [id://839391]=note: print w/replies, xml ) Need Help??


in reply to Split Help

It's not exactly clear to me how you want to extract www.abcd.com.ppt from www.abcd.com/search, or www.efgh.in.doc from www.efgh.in#found... (looks like the .ppt and .doc should rather come from the content type of the page; also, what if there is more than one URL with the same host part?)

Anyhow, maybe the URI module could help.  It provides various methods for getting the path, etc. components of an URL.

Replies are listed 'Best First'.
Re^2: Split Help
by keeper12 (Novice) on May 11, 2010 at 08:12 UTC
    What I am trying to say is I want to extract www.abcd.com or www.efgh.in from the URLs using Split function.

    The URLs i am supposed fetch files from contain single files only. You are right that the .ppt and .doc will come from the content type of the page.

    What I want is if a '/' or A '#' is encountered wherever in the URL, the part before it should be taken as the filename. i.e

    if

    www.abcd.com?file/search is URL then www.abcd.com?file should be the file name.

    and if

    www.abcd.com/search is URL then www.abcd.com should be the file name. Same is the Case with '#'

    I want to split the URL at the first '/' or first '#' and use it.

    BTW Thank you for ur Reply
      I want to split the URL at the first '/' or first '#' and use it.

      Then maybe just try

      for my $url ("www.abcd.com?file/search", "www.abcd.com/search", "www.efgh.in#found") { my ($fname) = split /[\/#]/, $url; print $fname; } __END__ www.abcd.com?file www.abcd.com www.efgh.in

      split takes a regular expression by which to split the string, and [\/#] is a character class comprising the two characters '/' and '#', which means to split on either of those characters.  The parentheses around $fname in the assignment are needed to supply list context for split.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found