Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day JockoHelios,

From your original post and your replies to frozenwithjoy and LanX, you appear to be experiencing a fair amount of confusion. Perhaps this short annotated script might inject some clarity:

$ perl -Mstrict -Mwarnings -le ' use Data::Dumper; # Declare an empty array (Note: no "splice" required) my @records; # Initialise the array with 2 elements # Each element must be a scalar # If an element is an array of values, you need an arrayref @records = ( [ "A", 1, 2, 3 ], [ "B", 4, 5, 6 ] ); print "\$records[1][2]: ", $records[1][2]; # Push another array of values (as an arrayref) push @records, [ "C", 7, 8, 9 ]; print "\$records[2][2]: ", $records[2][2]; # "join" creates a string (strings are scalar values) push @records, join ",", "D", 10, 11, 12; print "\$records[3]: ", $records[3]; # Add a hash (as a hashref - which is also a scalar value) push @records, { E => 13, F => 14, G => 15 }; print "\$records[4]{G}: ", $records[4]{G}; # The entire data structure: print Dumper \@records; ' $records[1][2]: 5 $records[2][2]: 8 $records[3]: D,10,11,12 $records[4]{G}: 15 $VAR1 = [ [ 'A', 1, 2, 3 ], [ 'B', 4, 5, 6 ], [ 'C', 7, 8, 9 ], 'D,10,11,12', { 'G' => 15, 'F' => 14, 'E' => 13 } ];

See also: splice, join, perldsc - Perl Data Structures Cookbook.

-- Ken


In reply to Re: element of an array of arrays by kcott
in thread element of an array of arrays by JockoHelios

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 studying the Monastery: (8)
As of 2024-03-28 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found