Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: strict or not strict?

by xdg (Monsignor)
on Aug 19, 2005 at 14:32 UTC ( #485158=note: print w/ replies, xml ) Need Help??

in reply to Re^2: strict or not strict?
in thread strict or not strict?

If the variables are declared already above your loop, then you can do it via string eval. E.g.

#!/usr/bin/perl use strict; use warnings; my ($blah, $boo, $hoo); # DECLARED HERE my %data = ( "blah"=>1, "boo"=>2, "hoo"=>3 ); # assign each key to a variable of the same name foreach (keys %data) { eval " \$$_ = \$data{$_} "; } # end-foreach print $blah; exit;

Replace is still probably a better long run strategy.


Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Comment on Re^3: strict or not strict?
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2016-05-30 05:13 GMT
Find Nodes?
    Voting Booth?