Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: What is this doing, and why is this a good method of doing it?

by IOrdy (Friar)
on Jul 25, 2005 at 02:05 UTC ( [id://477652]=note: print w/replies, xml ) Need Help??


in reply to What is this doing, and why is this a good method of doing it?

I'll bite, rather than switching strict refs off then on again is it a good method? Is there a side effect of switching I dont see?

for (@x) { no strict 'refs'; *$_ = sub { use strict 'refs'; # ... }; }
Also why is the semicolon required before the no strict 'refs'?

Replies are listed 'Best First'.
Re^2: What is this doing, and why is this a good method of doing it?
by japhy (Canon) on Jul 25, 2005 at 02:11 UTC
    Because at compile-time, when Perl has parsed the no strict 'refs' part, it realizes it was inside a *{...} construct, the inside of which can be a block or an expression. Since it expects it to have been an expression, the use of no raises a compile-time error. To force Perl to realize the interior is a block, the ; is added to the beginning.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re^2: What is this doing, and why is this a good method of doing it?
by Anonymous Monk on Jul 25, 2005 at 12:36 UTC
    The difference is that here the defined sub has use strict 'refs' in effect, while in Japhy's original code, the defined sub has ref strictness in effect if, and only if, ref strictness is in effect just before the for loop.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-03-19 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found