Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: Storing Info with Accessors

by bikeNomad (Priest)
on Aug 02, 2001 at 17:34 UTC ( [id://101643]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Storing Info with Accessors
in thread Storing Info with Accessors

Since no strict 'refs' only affects the block it's in, it won't affect the rest of your program (past the next curly brace, anyway). I make a practice of putting it in the innermost scope possible. You can do the following instead if you're paranoid. Note that the no strict 'refs' only affects the one line with the assignment. Why would you hesitate to use that? I hope you're not absorbing the 'always use strict everywhere' dogma...

foreach my $field ( keys %orderObjectFields ) { my $default = $orderObjectFields{$field}; my $closure = sub { my $value = ( scalar @_ > 1 ? $_[0]->{$field} = $_[1] : $_[0]->{$fie +ld} ); $value = $default unless defined $value; $value; }; no strict 'refs'; # only affects next statement: *{ __PACKAGE__ . "::$field" } = $closure; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found