I have a program set up to run through a file containing a list of tests to run, with some of the tests in different folders. I want to set up an array of hashes to do this. Here's how I have it set up:
my $test_list = "some_tests";
open TESTS, $test_list or die "Can't open $test_list: $!\n";
my @tests;
while (<TESTS>) {
my %tests;
next if /^\s*$/;
my $temp = $_;
if ($_ =~ /\//) {
$temp =~ s/\/.*//;
chomp $temp;
s/.*\///;
}
else {
$temp = "*";
}
chomp;
$tests{$_} = $temp;
push @tests, %tests;
}
close TESTS;
my $count = 0;
for (@tests) {
$count++;
my %tests = $_;
my ($test, $category) = each %tests;
print "Starting $test... ($count/@{[scalar @tests]})\n";
print "Test: " . $test . "\n";
print "Category: " . $category . "\n";
}
I can't quite seem to get this working properly, though. I've tried using each directly on $_, as well, with no success. It seems to work fine up until the point that it tries to print out $category. Perl gives me a warning that it has not been initialised. I've checked Perldoc and searched through SOPW, and found precious little information on arrays of hashes. If anyone could help, I'd be most appreciative. I'm running Perl 5.8.0 on Irix 6.5
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.