Here's an example of creating a data structure similiar to what you're talking about, and popping and pushing elements into it.
I also tend to prefer the arrow notation, rather than the implicit mode. I believe the arrow notation makes it more clear. But that may be my 'C' background talking.
Update: Looks like I was too slow. Oh well.
#!/usr/local/bin/perl -w
use strict;
use Data::Dumper;
{
my @arr = ({-a => [qw(a1 a2 a3)]}, {-b => [qw(b1 b2 b3)]}, {-c => [
+qw(c1 c2 c3)]});
print "Dumping initial data structure -->\n";
print Dumper ([\@arr]), "\n";
print "Displaying elements of @arr [1]->{-b} -->\n";
print "$_\n" foreach (@{$arr [1]->{-b}});
print "\n";
pop (@{$arr [2]->{-c}});
print "Dumping data structure with @arr[2]->{-c} popped (no c3) -->
+\n";
print Dumper ([\@arr]);
push @{$arr [0]->{-a}}, "a4";
print "Dumping data structure with a4 added to @arr[0]->{-a} -->\n"
+;
print Dumper ([\@arr]);
}
--Chris
e-mail jcwren
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.