it might be better to use a named capture here since you're expecting
certain things and then you don't have to do if defined.

On Sun, Dec 23, 2012 at 5:43 PM, Zachary Bornheimer <z...@chary.me> wrote:
> For this error, try something like this:
>
> Take note of any regex changes that you were advised in other emails
>
> if ( $line =~ /AccessModes\s*=\s*.*(WebMail)*.*(POP).*(WebMail)*.*/ ) {
>     if (defined $2 && $2 && $1 ) {
>         print $2 . " " . $1 . $line . "\n";
>     }
> }
>
> Make sure that $2 is initialized.  $2 may be defined, but not initialized.
>  Because $2 cannot be defined if $1 is not defined, we don't need to check
> if $1 is defined, but we should check if it is initialized.  (Note, I
> didn't make this my style, but I did change it a little).
>
>
> ## Z. Bornheimer
>
>
> On Sun, Dec 23, 2012 at 8:27 AM, punit jain <contactpunitj...@gmail.com>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 ?
>>
>> Regards.
>>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to