in reply to Most efficient way of search elements in an array
So close, yet so far :)
If you're using Perl 5.10, you can use the "Smartmatch Operator" ~~ instead of =~ and your program will work:
use strict; for my $testcase ([1,1,1,0,1],[1,1,1,1,1],[1,10,101]) { my @results_file = @$testcase; if (@results_file ~~ m/0/) { print"\n--FAIL-- @results_file"; } else { print "\n--PASS--STATUS\n"; print "\n@results_file\n"; } }
The only relevant change is from @results_file =~ /0/ to @results_file ~~ /0/. You might want to consider anchoring your match, so you match only a 0, and not 100, or 101.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Most efficient way of search elements in an array
by AnomalousMonk (Archbishop) on Sep 15, 2009 at 15:06 UTC |