On 23/12/2012 13:27, punit jain wrote:
Hi,
I am doing grouping but seeing some weird behavior :-
the strings in a file are like :-
AccessModes =
(18,Mail,POP,IMAP,PWD,WebMail,WebSite,Relay,Mobile,FTP,MAPI,TLS,LDAP,WebCAL);
....
...
.
multiple lines
I am seeing which lines have both POP and Webmail as below :-
if( $line =~ /AccessModes\s*=\s*.*(WebMail)*.*(POP).*(WebMail)*.*/ ) {
if(defined $2) {
print "$2 $1"."$line"."\n";
}
}
However I get these below :-
POPUse of uninitialized value in concatenation (.) or string at
test.plline 283, <GEN85> line 2.
POPUse of uninitialized value in concatenation (.) or string at
test.plline 283, <GEN86> line 2.
POPUse of uninitialized value in concatenation (.) or string at
test.plline 283, <GEN87> line 2.
Any clue why ?
You would be bettre off using a look-ahead, which doesn't care what
order the two options appear in the list. The program below shows an
example.
Rob
use strict;
use warnings;
while (my $line = <DATA>) {
if ($line =~ /AccessModes\s*=\s*(?=.*(\bPOP\b))(?=.*(\bWebMail\b))/) {
print "$1 $2\n";
}
}
__DATA__
AccessModes =
(18,Mail,POP,IMAP,PWD,WebMail,WebSite,Relay,Mobile,FTP,MAPI,TLS,LDAP,WebCAL);
AccessModes =
(18,Mail,IMAP,PWD,WebMail,WebSite,Relay,Mobile,FTP,MAPI,TLS,LDAP,POP,WebCAL);
**output**
POP WebMail
POP WebMail
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/