Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: grep surprise

by dbuckhal (Hermit)
on Nov 12, 2018 at 18:37 UTC ( #1225652=note: print w/replies, xml ) Need Help??


in reply to Re^3: grep surprise
in thread grep surprise

How about the value of verbosity?
$ perl -we ' use strict; my @array=(1,2); my $matches = 0; for my $ea (1..3) { $matches = grep { printf("idx: %d, val: %d == %d? %3s, ", $_, $array[$_], $ea, ($array[$_] == $ea) ? "YES" : "NO"); $array[$_] == $ea; } (0..$#array); print "matches: $matches\n"; } ' __output__ idx: 0, val: 1 == 1? YES, idx: 1, val: 2 == 1? NO, matches: 1 idx: 0, val: 1 == 2? NO, idx: 1, val: 2 == 2? YES, matches: 1 idx: 0, val: 1 == 3? NO, idx: 1, val: 2 == 3? NO, matches: 0

and who ever said Perl was not readable... :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1225652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2019-10-22 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?