J
J.D. Baldwin
I solved my problem by rewriting, but I'm wondering why I am getting errors
with respect to 'ne' and 'eq' operators.
This code works fine (Perl 5.8.8):
$ cat minimal.pl
#!/opt/gnu/bin/perl
use warnings;
use strict;
my $VAL = 'xyz';
my @foo = ( 'abc', 'def', 'ghi', 'xyz', 'jkl', 'xyz', 'uvw' );
foreach my $item ( @foo )
{
next if ( $item ne $VAL );
print "$item\n";
}
$ ./minimal.pl
xyz
xyz
But if I add a test for 'undef' I get warnings:
$ cat ./minimal2.pl
#!/opt/gnu/bin/perl
use warnings;
use strict;
my $VAL = 'xyz';
my @foo = ( 'abc', 'def', 'ghi', 'xyz', 'jkl', 'xyz', 'uvw' );
foreach my $item ( @foo )
{
next if ( undef $item ) or ( $item ne $VAL );
print "$item\n";
}
$ ./minimal2.pl
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Even weirder if I try 'eq':
$ cat ./minimal3.pl
#!/opt/gnu/bin/perl
use warnings;
use strict;
my $VAL = 'xyz';
my @foo = ( 'abc', 'def', 'ghi', 'xyz', 'jkl', 'xyz', 'uvw' );
foreach my $item ( @foo )
{
next if ( undef $item ) or ( $item eq $VAL );
print "$item\n";
}
$ ./minimal3.pl
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Can anyone explain to me why I see this behavior? It seems like a
perfectly normal chained test.
with respect to 'ne' and 'eq' operators.
This code works fine (Perl 5.8.8):
$ cat minimal.pl
#!/opt/gnu/bin/perl
use warnings;
use strict;
my $VAL = 'xyz';
my @foo = ( 'abc', 'def', 'ghi', 'xyz', 'jkl', 'xyz', 'uvw' );
foreach my $item ( @foo )
{
next if ( $item ne $VAL );
print "$item\n";
}
$ ./minimal.pl
xyz
xyz
But if I add a test for 'undef' I get warnings:
$ cat ./minimal2.pl
#!/opt/gnu/bin/perl
use warnings;
use strict;
my $VAL = 'xyz';
my @foo = ( 'abc', 'def', 'ghi', 'xyz', 'jkl', 'xyz', 'uvw' );
foreach my $item ( @foo )
{
next if ( undef $item ) or ( $item ne $VAL );
print "$item\n";
}
$ ./minimal2.pl
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Use of uninitialized value in string ne at ./minimal2.pl line 12.
Even weirder if I try 'eq':
$ cat ./minimal3.pl
#!/opt/gnu/bin/perl
use warnings;
use strict;
my $VAL = 'xyz';
my @foo = ( 'abc', 'def', 'ghi', 'xyz', 'jkl', 'xyz', 'uvw' );
foreach my $item ( @foo )
{
next if ( undef $item ) or ( $item eq $VAL );
print "$item\n";
}
$ ./minimal3.pl
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Use of uninitialized value in string eq at ./minimal3.pl line 12.
Use of uninitialized value in concatenation (.) or string at ./minimal3.pl line 14.
Can anyone explain to me why I see this behavior? It seems like a
perfectly normal chained test.