in reply to Re: problem with variable values
in thread problem with variable values
A function should take arguments and return a result or perform an action that depends solely on these arguments.My own view is less extreme. For instance, the standard way to produce a variable in a subroutine that remembers its values between calls is as follows:
use strict; # tested on 5.6/win print mysub(); print "\n" . mysub(); {my $persistentVariable; sub mysub { $persistentVariable++; } }
There are other uses as well for declaring a variable used by a subroutine outside of that subroutine. For instance, since an anonymous subroutine is only compiled once, any such variable when called in an anonymous subroutine will preserve whatever value it had at the time the subroutine was declared.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 3: problem with variable values
by tilly (Archbishop) on Jun 14, 2001 at 00:08 UTC | |
by sierrathedog04 (Hermit) on Jun 14, 2001 at 00:52 UTC |