in reply to ptkdb: 'my' variable in sub retains value between calls

my $a,$b; doesn't declare $b, only $a. Had you included
use strict; use warnings;

at the start of the program (see strict and warnings), perl would have told you "Parentheses missing around "my" list ...". The correct way is my ($a, $b);. But, $a and $b aren't good names to use as they are somewhat magical for their use with sort. You should choose more meaningful names.


Unless I state otherwise, all my code runs with strict and warnings

Replies are listed 'Best First'.
Re^2: ptkdb: 'my' variable in sub retains value between calls
by leonidlm (Pilgrim) on Aug 10, 2008 at 16:11 UTC
    Thank you all. The variable names are just for an example, of course I used a proper names in my program, it is more than 2000 lines, I don't think I would manage elsewhere.

      $foo and $bar are good time honored place holder names for variables and are almost as easy to type as $a and $b.


      Perl reduces RSI - it saves typing
      If, in addition to using warnings with its very helpful message referred to in other replies, you had been using strict, Perl would never have let you make the mistake in the first place if you were using names other than $a and $b!