Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: About "state" variables in Perl 5.10

by exussum0 (Vicar)
on Dec 28, 2007 at 18:46 UTC ( #659376=note: print w/replies, xml ) Need Help??


in reply to About "state" variables in Perl 5.10

Neat. C style static variables. I do have one curious thought. Didn't oop solve this via objects/classes? Was there a great demand for it? What inspired this neat little feature?
  • Comment on Re: About "state" variables in Perl 5.10

Replies are listed 'Best First'.
Re^2: About "state" variables in Perl 5.10
by grinder (Bishop) on Dec 28, 2007 at 22:30 UTC

    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

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://659376]
help
Chatterbox?
[hippo]: +1 for Text::CSV_XS
[ovedpo15]: Im not allowed to use additional modules, so I can't use it. looking for a simple regex to do this task though..
[Corion]: Ah, so this is homework? Then most likely, you should review your course material closer. It would greatly surprise me if the course material wouldn't mention the topics that will be used in the homework...
[Corion]: I already showed you the simple regex to match the last part of a string without a comma in it
[Tux]: Corion++ hippo++
[ovedpo15]: it isn't homework. its a module I use at work. The process to add additional module isn't worth it. p.s never heard a university course which teach perl
[marto]: there are many, to this day.
[ovedpo15]: @Corion Yes I use the regex you showed me. its very good regex. although now i need to know that substring unit that comma
marto mad corrections to one around 18 months ago
[ovedpo15]: my code checks the value after that comma, if it isn't valid it will remove it. so I would like to remove the substring after that comma meaning getting the string before comma.

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2018-05-27 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?