Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Localizing hash keys in an AoH

by kennethk (Abbot)
on Mar 15, 2013 at 20:58 UTC ( #1023777=note: print w/replies, xml ) Need Help??


in reply to Re: Localizing hash keys in an AoH
in thread Localizing hash keys in an AoH

When you localize the array, it's only the array elements that get localized; you still have the original hash refs.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; our @data = ( {unit => 'S', value => 50, }, {unit => 'T', value => 60, }, {unit => 'Q', value => 70, }, ); LOCAL_BLOCK: { local(@data) = @data; $_->{unit} = 'S' for @data; } print Dumper \@data;
outputs
$VAR1 = [ { 'unit' => 'S', 'value' => 50 }, { 'unit' => 'S', 'value' => 60 }, { 'unit' => 'S', 'value' => 70 } ];

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023777]
help
Chatterbox?
choroba waves is
[choroba]: 'Tyrol' =~ tr/Ty o/Pe/rd
choroba hates the CB and its space insertion
Eily wondered if the space was there for a reason
[Eily]: like "Replace the T, replace the y, skip one, replace the o"
[Discipulus]: it works anyway, good morning choroba

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2017-07-24 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (348 votes). Check out past polls.