in reply to increasing value every time sub routine called

sub increaseNumber { my $value = 001 return $value + 1 };

Every time you call that sub, you (re)set $value to one.

If you did it this way:

my $value = 1; sub increaseNumber { return ++$value; };

It would work as you want.

Why post pseudo-code rather than proper Perl?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: increasing value every time sub routine called
by bigmoose (Acolyte) on Dec 09, 2011 at 12:49 UTC

    I worked it out :)

    increase(); increase(); increase(); sub increase { $n += 1; # Global variable $n print "$n\n"; }