Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: Bring Out Your New Perl Code

by sgt (Deacon)
on Dec 20, 2007 at 00:13 UTC ( #658021=note: print w/replies, xml ) Need Help??

in reply to Re^2: Bring Out Your New Perl Code
in thread Bring Out Your New Perl Code

Actually you should compare using a bare block (no BEGIN) which is the standard (older) way to have "state" variables.

I like 'state' but the old way is still useful if you need a pair of cooperating subs (or more):

% steph@ape (/home/stephan) % % cat state_old.px #!/usr/bin/perl+ { my $var = 10; sub next1 { ++$var; } sub next1_odd { if ($var % 2 == 0) { ++$var; } else { ++$var; ++$var; } } } $\ = qq{\n}; print next1() for 1..5; print next1_odd(); % steph@ape(/home/stephan) % % perl+ -w state_old.px 11 12 13 14 15 17
cheers --stephan

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://658021]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2023-04-01 17:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found