Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: scoping problem?

by AnomalousMonk (Archbishop)
on Dec 06, 2011 at 19:19 UTC ( [id://942083]=note: print w/replies, xml ) Need Help??


in reply to Re: scoping problem?
in thread scoping problem?

Does the text file contain a blank line?

rocroc:
Here's an example of behavior when processing a blank line or a line having empty or too few fields: an empty or missing field splits to an empty string or to undef. The reason for the seemingly spurious match is that an empty string or an undef becomes the // regex, which always matches!

>perl -wMstrict -le "my $s = 'foo,,'; ;; my ($field0, $field1, $field2, $field3) = split /,/, $s; print qq{field0 '$field0' field1 '$field1' field3 '$field3'}; ;; if ('bar' =~ m{ $field1 }xms) { print qq{bar matches '$field1'} } if ('bar' =~ m{ $field3 }xms) { print qq{bar matches '$field3'} } " Use of uninitialized value $field3 in concatenation (.) or string ... field0 'foo' field1 '' field3 '' bar matches '' Use of uninitialized value $field3 in regexp compilation ... Use of uninitialized value $field3 in concatenation (.) or string ... bar matches ''

Note that without warnings (you are using warnings, aren't you?), this all proceeds quite silently:

>perl -Mstrict -le "my $s = 'foo,,'; ;; my ($field0, $field1, $field2, $field3) = split /,/, $s; print qq{field0 '$field0' field1 '$field1' field3 '$field3'}; ;; if ('bar' =~ m{ $field1 }xms) { print qq{bar matches '$field1'} } if ('bar' =~ m{ $field3 }xms) { print qq{bar matches '$field3'} } " field0 'foo' field1 '' field3 '' bar matches '' bar matches ''

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://942083]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-19 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found