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.