Saturday, July 23, 2011

To extract all occurence of word from string perl

#To extract occurence of word from string
#To extract a occurence of word from a string it is very easy in perl.We need to search the occurence in global way.
#For example to extract all occurence of emailid from a string
Content of the perl file:

$dd='karthik lijo james thomas';
while ( $dd =~ /\s+(\S*\@\S*.com)\s+/g )
print $1."\n";




Here i have used the pattern /\s+(\S*\@\S*.com)\s+/g  to extract all email-ids from the scalar $dd.Here g signifies globally match all the email -ids from the string. 

No comments:

Post a Comment