Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Little annoying mistakes ... of others

by jeffa (Chancellor)
on Dec 07, 2008 at 16:06 UTC ( #728735=note: print w/ replies, xml ) Need Help??


in reply to Re: Little annoying mistakes ... of others
in thread Little annoying mistakes ... of others

Actually ... i would desire this:

use strict; use warnings; my $arg = shift || 'boo'; my @valid = qw( goo moo foo voo doo poo ); print "$arg matches\n" if grep /$arg/, @valid;

But this bring up an annoyance as well, because this mistake will compile and always return true (as long as the array being checked is not empty):

# wrong way ahead! print "$arg matches\n" if grep $arg, @valid;
Oops!

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on Re^2: Little annoying mistakes ... of others
Select or Download Code
Re^3: Little annoying mistakes ... of others
by szabgab (Priest) on Dec 28, 2008 at 19:26 UTC
    Wow, I am writing down the examples as test cases but I can't figure out why is the second example always true?

    could you please explain?

      I think this:

      print "$arg matches\n" if grep $arg, @valid;

      Is equivalent to this:

      print "$arg matches\n" if grep { $arg } @valid;
      So as long as @valid and $arg are not false, then the match will also be true. (If $arg is 0 (zero) then the second example will not always be true.)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2015-07-06 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls