|
Posted by Tad J McClellan on March 8, 2008, 8:56 pm
Please log in for more thread options
>> Hi,
>>
>> my $url = "/pages-cell.net/deepan/sony/";
>>
>> if($url =~ m/\/(.*)\//g)
>> {
>> my @result = $1;
>> return @result;
>> }
>>
>> What i need is that i should be able to get anything that is between /
>> and /. Here i should be able to get pages-cell.net,deepan,sony into
>> @result but something is wrong somewhere. Please help me to solve
>> this?
>>
> No. m\/(.*)\//g only returns one string; m *always* only returns one
> string.
No it doesn't.
The m// operator always returns one string when in scalar context.
(in fact, *every* operator can return only one thing in scalar context.)
m// in list context can potentially evaluate to more than one string.
---------------
#!/usr/bin/perl
use warnings;
use strict;
$_ = 'foo bar';
my @matches = m/(\w+)\s+(\w+)/;
foreach (@matches) {
print "$_\n";
}
---------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"
|