Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 ;

 
______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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-29 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found