nysus has asked for the wisdom of the Perl Monks concerning the following question:
When I tried printing @common using the following data:@common = inter ( \%foo, \%bar, \%joe ); sub inter { my %seen; for my $href (@_) { while (my $k = each %$href ) { $seen{$k}++; } } return grep { $seen{$_} == @_ } keys %seen; } =======================================================
@common came back null for me. However, when I changed this line:__DATA__ my %foo = ( 'one' => 1, 'two' => 2, 'three' => 3, ); my %bar = ( 'two' => 5, 'four' => 6, ); my %joe = ( 'three' => 7, 'four' => 8, 'five' => 89, );
return grep { $seen{$_} == @ } keys %seen;
to this:
return grep { $seen{$_} } keys %seen;
@common returned:
which judging by the description in the book, appears to be what the code is supposed to yield. I find it hard to believe I would catch an error like this. Can someone please back me up on this?three five one two four
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot";
$nysus = $PM . $MCF;
Edit by tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Code mistake in Camel book?
by wog (Curate) on Jun 26, 2001 at 08:42 UTC | |
by nysus (Parson) on Jun 26, 2001 at 08:59 UTC | |
by tilly (Archbishop) on Jun 26, 2001 at 15:39 UTC | |
by tye (Sage) on Jun 26, 2001 at 19:56 UTC |