EvdB has asked for the wisdom of the Perl Monks concerning the following question:
Then I read About variable names and got worried again.
This morning I was burnt by this gotcha (code has been simplified):
Because when you run it you get this from the warnings:use strict; # line 1 use warnings; # line 2 # line 3 my $value1 = 'foo'; # line 4 my $value2 = undef; # line 5 # line 6 if ( $value1 eq 'bar' ) { # line 7 print 'value1 is bar'; # line 8 # line 9 } elsif ( $value2 eq 'bar' ) { # line 10 print 'value2 is bar'; # line 11 # line 12 } # line 13
But the 'undef in string eq' is on line 10! ( This took quite a while to debug ).[evdb@desktop evdb]$ perl test.pl Use of uninitialized value in string eq at test.pl line 7.
I ask you, what other perl gotchas are there out there that could bite me?
PS: I've looked at Regular Expression gotchas, Common Regex Gotchas and others from seaching for 'gotcha'.
--tidiness is the memory loss of environmental mnemonics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Gotchas.
by liz (Monsignor) on Nov 20, 2003 at 15:06 UTC | |
by tilly (Archbishop) on Nov 20, 2003 at 15:32 UTC | |
|
Re: Perl Gotchas.
by mpeppler (Vicar) on Nov 20, 2003 at 15:35 UTC | |
by Anonymous Monk on Nov 20, 2003 at 17:22 UTC | |
by mpeppler (Vicar) on Nov 20, 2003 at 17:46 UTC | |
by b10m (Vicar) on Nov 20, 2003 at 19:34 UTC | |
by bart (Canon) on Nov 20, 2003 at 21:49 UTC | |
by ambrus (Abbot) on Nov 22, 2003 at 21:28 UTC | |
|
Re: Perl Gotchas.
by Zed_Lopez (Chaplain) on Nov 20, 2003 at 18:52 UTC | |
|
Re: Perl Gotchas.
by hardburn (Abbot) on Nov 20, 2003 at 15:08 UTC | |
by pg (Canon) on Nov 20, 2003 at 17:45 UTC | |
by rob_au (Abbot) on Nov 21, 2003 at 00:35 UTC | |
|
Re: Perl Gotchas. (if( condition) { bug })
by grinder (Bishop) on Nov 20, 2003 at 17:31 UTC | |
by EvdB (Deacon) on Nov 20, 2003 at 18:19 UTC | |
by chromatic (Archbishop) on Nov 20, 2003 at 18:57 UTC | |
by EvdB (Deacon) on Nov 20, 2003 at 19:05 UTC | |
by jeffa (Bishop) on Nov 20, 2003 at 20:31 UTC | |
| |
by Aristotle (Chancellor) on Nov 21, 2003 at 15:01 UTC |