global - The good, the bad, and the ugly of lexical $_ in Perl 5.10+ -


Starting in Perl 5.10, it is now possible that the reference variable $ _ , either explicit By form my $ _; In the creation of or given / when .

Did anybody get good use of Likhax $ _ ? Does it make any composition simple / safe / fast?

What about the situations that make it more complicated? Did Likhax $ _ start any bug in your code? (Since the control structures that write $ _ are used in the inbound version, it can change the behavior of the code if it contains a sub-routine call (due to lack of dynamic area)

Finally, I want to create a list that explains that when $ _ is used as a word, globally, Or when it does not matter.


NB: As of perl5-5.24 these are experimental features.

$ _ The thing is the new _ prototype symbol.

This allows you to specify a subtitle so that it can take a scalar Or if no one has been provided, it will receive $ _ .

subfoo {my $ arg = @_ ? Change: Do stuff with $ _; # $$

I write Awareness I:

  sub foo (_) {my $ arg = shift; # Goods $ _ or first with arguments}  

There is no big change, but when this behavior is what I want it is very easy. Removing a boilerplate is a good thing.

Of course, there is the effect of changing the prototype of many bilts (like chr ), which can break some code.

Overall, I welcome the lexical $ _ . It gives me a tool that I can use to control accidental data and limit the strange conversation between tasks. If I decide to use $ _ in the body of the function, then I can be sure that the code I call is modified in $ _ Calling code will not be done.

The dynamic scope is interesting, but for the most part I want lexical scrapping. Add complexity around this to $ _ I have local $ _; Have severe warnings about the inevitability of doing this - instead of using ($ foo) {} is best lexicalized $ _ Want 100 to 99 times, when I have localized $ _ in any way, lexical $ _ makes an impressive feature and readability feature even stronger.

The big part of my work has to be worked with Pearl 5.8, so I'm not happy to play with big text in code $ _ However, it seems that This will set a long way to securing $ _ which is a good thing.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -