Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: About "state" variables in Perl 5.10

by grinder (Bishop)
on Dec 28, 2007 at 22:30 UTC ( #659422=note: print w/replies, xml ) Need Help??

in reply to Re: About "state" variables in Perl 5.10
in thread About "state" variables in Perl 5.10

One particular itch that needed scratching, apart from some of the points that TimToady makes, is that it got rid of the ugly state-with-a-my hack that went something like:

my $persist if 0;

That particular construct breaks through the abstraction of the language and hits an oddity in the way lexicals are implemented. The result of which was, when used in a routine, a variable that maintained its previous value next time the routine was called.

It was a sufficiently desirable trick that it was independently discovered time and again, by people who understood the language sufficiently deeply, and tried it out and were happy to discover that it worked.

Unfortunately, it was also regularly discovered by people who had no idea what was going on, and it led to bugs that were difficult to understand and fix (especially when the if 0 was buried under a complex expression).

So one of things that went into 5.10 was the outlawing of my $foo if 0 to stop people shooting themselves in the foot, and the introduction of state variables, for those who needed them.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^3: About "state" variables in Perl 5.10 (!0?)
by tye (Sage) on Dec 29, 2007 at 03:18 UTC
    So one of things that went into 5.10 was the outlawing of my $foo if 0

    Why still allow my $foo if $bar; ? Such seems, if anything, worse than the if 0 construct. I can understand putting it through a deprecation cycle but not even that was started.

    - tye        

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-05-13 17:55 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (137 votes). Check out past polls.