Basically, all you're pushing onto your array, is the same hashref over and over and over again, whose values you redefine, over and over and over and over again.#!/usr/bin/perl -w use strict; $\="\n"; my %jar = qw( a b c d); my @ppp = ( \%jar ); print a => $jar{a}; print a => $ppp[0]->{a}; print c => $jar{c}; print c => $ppp[0]->{c}; $jar{a}='gork'; $jar{c}='gork'; push @ppp, \%jar; print a => $jar{a}; print a => $ppp[0]->{a}; print a => $ppp[1]->{a}; print c => $jar{c}; print c => $ppp[0]->{c}; print c => $ppp[1]->{c}; { my %jar = ( a => shark => c => shark => 1 => 2 ); push @ppp, \%jar; } print a => $jar{a}; print a => $ppp[0]->{a}; print a => $ppp[1]->{a}; print a => $ppp[2]->{a}; print c => $jar{c}; print c => $ppp[0]->{c}; print c => $ppp[1]->{c}; print c => $ppp[2]->{c};
Now your hash is not a global, even though you kind of treat it as such (globals live in the package namespace, they aren't declared with my, they're declared with use vars '%global', or our(%global), or %package::name::global).
Before you push @stories, \%story, you could simply create a new hash, and push it's reference onto @stories. Example
use strict; $\="\n"; my %f = 1..4; print \%f; my %b = %f; print \%b; print they => are => not => equal => chr(33) if \%b ne \%f ;
| ______crazyinsomniac_____________________________ Of all the things I've lost, I miss my mind the most. perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;" |
In reply to (crazyinsomniac: perlref) Re: Problem with a Ref to a global variable while using XML::Parser
by crazyinsomniac
in thread Problem with a Ref to a global variable while using XML::Parser
by beamsack
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |