mc has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl
use strict;
my @list = qw(1 Mike testing 2 Richard testing2 3 David Testing3);
my @records;
my $r = {};
my $c = 1;
LOOP: foreach my $f (@list) {
if ($c == 1) { $r->{id} = $f }
if ($c == 2) { $r->{name} = $f }
if ($c == 3) {
$r->{subject} = $f;
print "Pushing Id: $r->{id}\t Name: $r->{name}\t Subject: $r->{subject}\n";
push(@records, $r);
$c = 1;
next LOOP;
}
$c++;
}
for (my $i = 0; $i <= 2; $i++) {
print "ID: $records[$i]->{id} ";
print "Name: $records[$i]->{name} ";
print "Subject: $records[$i]->{subject}\n";
}
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Array of hash
by chromatic (Archbishop) on Mar 24, 2000 at 22:33 UTC | |
|
RE: Array of hash
by mc (Initiate) on Mar 24, 2000 at 21:57 UTC |