in reply to Perl Switch Errors on certain version
I second getting rid of the switch($subkey)
There's no harm in using:
Also, in the 150 block where you have:if ( $subkey eq 1 ) { ... } elsif ( $subkey eq 11 ) { ... } ...
down to:elsif($new1 == /1/){
What are you expecting the string to be and what trying to test? ... a text match anywhere on the string:elsif($new1 == /9/){
or a test for the actual exact number?elsif($new1 =~ /1/){
or something else? I did this test myself how it would act:elsif($new1 eq 1){
and was quite surprised by the results!#!/usr/bin/perl -w use strict; for my $new1 qw(1 11 a1a 1aa 001 010) { print "$new1 == /1/ : "; if ( $new1 == /1/ ) { print "YES\n"; } else { print "NO\n"; } print "-" x 10, $/; print "$new1 == 1 : "; if ( $new1 == 1 ) { print "YES\n"; } else { print "NO\n"; } print "-" x 10, $/; print "$new1 =~ /1/ : "; if ( $new1 =~ /1/ ) { print "YES\n"; } else { print "NO\n"; } print "-" x 10, $/; print "$new1 eq /1/ : "; if ( $new1 eq /1/ ) { print "YES\n"; } else { print "NO\n"; } print "-" x 10, $/; print "$new1 eq 1 : "; if ( $new1 eq 1 ) { print "YES\n"; } else { print "NO\n"; } print "=" x 10, $/; }
actually fails with:if ( $new1 == /1/ )
if $new1 *is* 1 but on the other hand SUCCEEDS if $new1 is "a1a" !!!Use of uninitialized value in pattern match (m//) at ./try.pl line 8.
|
---|