in reply to Re: Array comparison for 3 arrays
in thread Array comparison for 3 arrays

Do not use map in void context. Although it probably doesn't generate the output list in current versions of Perl, it does send wrong signals about the intent of the code. Use for as a statement modifier instead:

$result->{$_}{$array_name} = 1 for @{$arrays->{$array_name}}
True laziness is hard work

Replies are listed 'Best First'.
Re^3: Array comparison for 3 arrays
by 7stud (Deacon) on Apr 14, 2010 at 07:23 UTC

    Don't use postfix for. :)

    my @array = $arrays->{$array_name}; for my $number (@array) { $result->{$number}->{$array_name} = 1 }

      There is no need to be excessively verbose when expounding on the subject at hand. It helps if you get the syntax right in your example code too.

      for my $number (@{$arrays->{$array_name}}) { $result->{$number}{$array_name} = 1; }

      The @{...} is required to dereference the array reference which is the hash value. Without the dereference syntax @array is assigned (or the loop iterates over) a single element which is the reference to the array.

      True laziness is hard work