in reply to 'my' problems

...The problem is that if I call the sub without the values 'limitstart' and 'limitantal' the STDERR row prints out ...

LIMIT = limit 20,20 || limitantal =

... I'd be surprised if this it true, you must have something else strange going on. Can you post a working example which demonstrates this?

---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re^2: 'my' problems
by jockel (Beadle) on May 23, 2005 at 10:18 UTC

    Hi Keith

    Wrote a small program that will reproduce the problem.

    #!/usr/bin/perl my $limitstart = 20; my $limitantal = 20; strange_sub(limitstart => $limitstart, limitantal => $limitantal); strange_sub(); sub strange_sub { my (%params) = @_; my $string = 'limit ' . $params{'limitantal'} if ((!$params{'l +imitstart'}) && ($params{'limitantal'})); $string = 'limit ' . $params{'limitstart'} . ", " . $params{'l +imitantal'} if (($params{'limitstart'}) && ($params{'limitantal'})); print STDERR "limitstring = " . $string . "\n"; }

    /jocke

      I'm surprised. :-o

      You have your answers below, but I'd thought I'd post a simple example, which shows quite explictly that the 'my' does scope a variable, but doesn't re-initialise it if you have a conditional which evaluates to false.

      print count() . "\n"; print count() . "\n"; print count() . "\n"; sub count { my $counter = 'whatever' if 0; # declare local 'static' variable $counter++; } __OUTPUT__ 0 1 2

      PS. Don't actually do this though

      ---
      my name's not Keith, and I'm not reasonable.