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

Re: Re: Re: Storing Info with Accessors

by bikeNomad (Priest)
on Aug 02, 2001 at 17:34 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-05-12 04:34 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (124 votes). Check out past polls.