Click here to get back home

Perl pattern extraction

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Perl pattern extraction Deepan - M.Sc(SE) - 03MW06 03-08-2008
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/"

Similar ThreadsPosted
Perl pattern matching and extraction March 8, 2008, 8:48 am
Pattern extraction March 10, 2008, 4:14 am
Pattern extraction March 10, 2008, 4:42 am
Pattern Matching and Extraction January 22, 2007, 2:51 pm
Help! Complex Pattern Extraction with Key/Value Pairs and Reg Exp? November 17, 2004, 6:10 pm
Column extraction in perl September 15, 2006, 12:31 pm
hiw do i perform this extraction August 21, 2006, 4:12 am
FTP Link Extraction January 20, 2007, 10:06 am
Statistics Extraction January 23, 2007, 3:25 pm
Help: Content extraction May 9, 2008, 10:30 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap