by Peter Wainwright et al. I decided to type in and run a hash example. The code looked like this:
p.135-136(Professional Perl Programming)
#!/usr/bin/perl
# indexhash.pl
use warnings;
use strict;
#create a hash with integrated index
my %hash = {
Mouse => {Index => 0, Value => 'Jerry'},
Cat => {Index => 1, Value => 'Tom'},
Dog => {Index => 2, Value => 'Spike'}
};
# sort a hash by integrated index
foreach (sort {$hash{$a} {'Index'} cmp $hash{$b} {'Index'}} keys %hash
+)
{
print "$hash{$_} {'Value'} <= $_ \n";
}
Perl told me the syntax was ok but when I ran it I got the following error messages:
Reference found where even-sized list expected at indexhash.pl line 7.
Use of uninitialized value in concatenatization (.) or string at index
+hash.pl line 16.
My question is twofold. First, assuming I can read and type what is the error? Second, does any Perl Monk have an opinion on this book and is it worth using?
This is my first post. I hope this question is suitable.
Thanks in advance,
xenchu
In reply to Book Code
by xenchu