Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Split Help

by keeper12 (Novice)
on May 11, 2010 at 08:12 UTC ( [id://839393]=note: print w/replies, xml ) Need Help??


in reply to Re: Split Help
in thread Split Help

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

Replies are listed 'Best First'.
Re^3: Split Help
by almut (Canon) on May 11, 2010 at 08:26 UTC
    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://839393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-23 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found