[Chicago-talk] Deprecated use of hash as a reference

Steven Lembark lembark at wrkhors.com
Thu Apr 8 09:17:45 PDT 2010


On Thu, 08 Apr 2010 09:42:44 -0500
Brad Doty <bdoty at eqtc.com> wrote:

> Speaking of PM as a source for assistance...
> 
> I was just composing a note to ask you guys how to solve a pesky warning
> in inherited code.  My fear of embarrassment in front of the entire
> group made me review my terms more precisely, which suggested a
> solution.  And it worked!
> 
> So thanks, ChicagoPM, for helping me solve my problem.
> 
> My solution is this
> 
> 940c940
> <old     push @{%hash->{$odate}}, {id => $id, ...
> ---
> >new     push @{{\%hash}->{$odate}}, {id => $id, ...
> 
> Any critiques or better ideas to avoid using hash as a reference?

{ \%hash }->{ $key } is equivalent to $hash{ $key }...

so:

    push @{ $hash{$key} }, $value;

will do just what you want.

or, to make it a bit clearer to the idiot that 
follows me (usually me) I usually extract the 
value into a more descriptive variable:

    my $purch   = { whatever info you like };

    my $hist    = $odate2purch{ $odate };

    push @$hist, $purch;

enjoi

-- 
Steven Lembark                                            85-09 90th St.
Workhorse Computing                                 Woodhaven, NY, 11421
lembark at wrkhors.com                                      +1 888 359 3508


More information about the Chicago-talk mailing list