Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Confusing grep behavior

by grep (Monsignor)
on Dec 04, 2007 at 21:19 UTC ( #654958=note: print w/replies, xml ) Need Help??

in reply to Confusing grep behavior

You need to reread grep
my @res = grep $_ split(",", "a,b,c,d,,f,,h"); #is a syntax error.

According to the POD when grep is not called with a block it requires a comma before the list you are working on.

So this will work as you expect.

my @res = grep $_, split(",", "a,b,c,d,,f,,h");
One dead unjugged rabbit fish later...

Replies are listed 'Best First'.
Re^2: Confusing grep behavior
by dextius (Monk) on Dec 04, 2007 at 23:33 UTC
    You are quite right.. I should rephrase my question... On Mac OS X, the comma isn't required, and has far different behavior. Anyone happen to know what that is?
      It's not a Mac thing. 5.8.5 on Linux allows it as well. I'm guessing it's a bug that was fixed in 5.8.7 or 5.8.8.
        Thanks, I wasn't aware of the bug, and was just confused since I wasn't getting a syntax error.

      No matter what OS you run it on the comma is still required, as noted by the POD and (quite noticeably) by the incorrect performance. The only difference(bug) is that it didn't throw an error. A crime is still a crime, whether you get caught or not :).

      One dead unjugged rabbit fish later...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://654958]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2018-06-22 23:13 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.