Amidamaru has asked for the wisdom of the Perl Monks concerning the following question:
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.5my $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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using an array of hashes
by Zaxo (Archbishop) on Oct 25, 2002 at 04:58 UTC | |
|
Re: Using an array of hashes
by grep (Monsignor) on Oct 25, 2002 at 05:03 UTC | |
by Amidamaru (Acolyte) on Oct 25, 2002 at 05:33 UTC | |
|
Re: Using an array of hashes
by jdporter (Paladin) on Oct 25, 2002 at 15:48 UTC |