in reply to Lotto checker...

If you change $draw into a hash, let's say to
my %draw = (map {$_ => 1} qw/ ... /);
you could count your hits easier with
... my $hits = @draw{@$bet}; ...
In addition, as already said, use for or foreach if you want to loop an array and map if you want to create a new list. And IMHO, don't use unnecessary refs if direct arrays or hashs will do it also. It just makes the code harder to read and to maintain.

Greetings,
Janek

Replies are listed 'Best First'.
Re^2: Lotto checker...
by kcott (Archbishop) on Apr 15, 2014 at 21:04 UTC
    my %draw = (map {$_ => 1} qw/ ... /);

    This is a good idea. [Minor point: the parentheses aren't necessary.]

    my $hits = @draw{@$bet};

    This is a less good idea: it isn't doing what you appear to think it does. See the following (and the examples that follow it) in "perldata: Slices":

    "Slices in scalar context return the last item of the slice."

    So, $hits will only ever equal 1 or undef, and the occasional correct output (e.g. "06 14 24 26 42 48 --> 1") will be just coincidence.

    Update: Just it case it isn't clear: in list context, @draw{@$bet} will always contain six elements, each of which will be either 1 or undef.

    -- Ken