Determine string in Perl.

Hi,

I have a little Perl question.
I need to determine the last word in the following string:

h t t p://abc.def.com/hijklm

The output should be the string hijklm.

h t t p is of course http.
The string between the slashes always differs.
The string after the last slash always differs.

Any idea how to do this ?

Best regards,

ejdv

I think u can use split and take the last index from array. array will be created after split

Hi ,

Try this

$str="h t t p://abc.def.com/hijklm";
@arr=split(/\//,$str);
print $arr[3];

Thanks
Penchal

Thanks a lot for the quick reply.
It did the job perfectly.

And $arr[-1] is the last element of @arr, no matter how many elements you ended up with. You could also use a regex match:

$str =~ m%([^/]*)$%;  print $1

This searches for characters adjacent to end of line ($) which are not slashes [^/] -- the * wildcard will match as many as possible.