First, I reccomend you sit down and read
perldata,
perlref, and skim through
perllol and
perldsc, and then consider this piece of code
#!/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};
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.
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 ;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.