Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 wandering the Monastery: (7)
As of 2015-07-06 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (72 votes), past polls