Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: using a string as a SCALAR ref while "strict refs" in use

by muba (Priest)
on Jun 19, 2012 at 12:32 UTC ( #977056=note: print w/ replies, xml ) Need Help??


in reply to using a string as a SCALAR ref while "strict refs" in use

Further down in that node (and in other search results) suggest using a hash. I really don't see how to do that in my case.

use strict; use strict; use warnings; use Data::Dump qw(pp); my %oldvalue = ( foo => "1", bar => "2", baz => "3" ); my %newvalue = ( foo => "A" ); foreach my $key (keys %oldvalue) { if (exists $newvalue{$key}) { $oldvalue{$key} = $newvalue{$key}; } } pp \%oldvalue; # { bar => 2, baz => 3, foo => "A" }

Or even simpler:

use strict; use warnings; use Data::Dump qw(pp); my %oldvalue = ( foo => "1", bar => "2", baz => "3" ); my %newvalue = ( foo => "A" ); %oldvalue = (%oldvalue, %newvalue); pp \%oldvalue; # { bar => 2, baz => 3, foo => "A" }


Comment on Re: using a string as a SCALAR ref while "strict refs" in use
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-09-22 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (180 votes), past polls