in reply to error message in the end of the array looping?

You need the string equality op, 'eq', not assignment, '='. You can keep track of how many matches you have by incrementing a variable in the true branch. As it's written, the else branch is unnecessary; control goes to the next iteration anyway.

my $counter; for (@array) { if ($hash{$_} eq "correct_value") { $counter++ print "$_ Success\n"; last; } } print 'We have a match.', $/ if $counter;

Update: Albannach++ quickly spotted an error, repaired.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: error message in the end of the array looping?
by polettix (Vicar) on May 30, 2006 at 10:42 UTC
    This surely popped somewhere else here in PM (I kinda remember something), but I did a supersearch for $/ without finding anything applicable. Why:
    print 'We have a match.', $/
    instead of
    print "We have a match.\n"
    (apart from TIMTOWTDI)? Pointers welcome!

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.

      Force of habit, mainly. I usually prefer giving print a list to concatenating strings and variables first. The habit just carries over to control characters like this, too.

      I used to believe that $/ had some advantage over "\n" in platform independence, but I'm over that now.

      After Compline,
      Zaxo