Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Instead of directly answering your question (which other people have already done, well) I'll give you a few quick pointers on perl references (which other people will probably also do). First, you might want to take a look at perlref, (i.e. type perldoc perlref), it contains a pretty good explanation of how to use references in perl.

Basically, references are scalars, if you have a C background, just think of them as pointers, the only difference being that you can't do pointer arithmetic on them. (i.e. no $myref++; or similar).

Also, since perl is not a strongly typed language, you are responsible for keeping track of what data type a reference points to. There's no such thing as an 'array reference' or a 'hash reference', just a reference, which can point to either an array or a hash.

Some examples of referencing and dereferencing

# create a 'real' array and a reference to it. my @array = (1, 2, 3, 4); my $reftoactualarray = \@array; # create a reference to an anonymous array my $reftoanonymousarray = [1, 2, 3, 4]; # both print the same thing print @$reftoactualarray; print @$reftoanonymousarray;
The difference between a 'real' array and an anonymous one is that when you modify the array referenced by $reftoactualarray, the contents of @array actually change. If you change the array referenced by $reftoanonymousarray, nobody else will see the changes you made. Dereferencing arrays of hashes or hashes of arrays, or any complex data structure like that, can get pretty hairy.

Good Luck,
Mark

Corrections welcome.


In reply to Re: Using an array in a hash by young perlhopper
in thread Using an array in a hash by Anonymous Monk

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 musing on the Monastery: (5)
As of 2023-12-03 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (20 votes). Check out past polls.

    Notices?