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.