in reply to Re: Bring Out Your New Perl Code
in thread Bring Out Your New Perl Code
It's the exact difference between the following two code snippets:
BEGIN { my $var = 10; sub next { return ++$var; } }
And the following:
sub next { state $var = 10; return ++$var; }
Now let's have a show of hands, how many people prefer the First Way To Do It? ... hmm, I see no hands? I thought as much :)
Tip o' the hat to Roy Johnson for pointing out that it was a BEGIN block I wanted, not an lexical scope with a label BEGIN:. And you do need a BEGIN block, not a bare block, otherwise you can run into grief with uninitialised values (which is kind of the whole point).
• another intruder with the mooring in the heart of the Perl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Bring Out Your New Perl Code
by sgt (Deacon) on Dec 20, 2007 at 00:13 UTC |