in reply to Re3: IF NOT! IF NOT!
in thread IF NOT! IF NOT!

Is it that grep returns a number when evaluated in a scalar context or that grep returns a list which, when evaluated in scalar context, gives the number of matches?

I know it sounds like a semantic difference, but I'm just curious.

------
/me wants to be the brightest bulb in the chandelier!

Replies are listed 'Best First'.
Re5: IF NOT! IF NOT!
by Hofmator (Curate) on Aug 03, 2001 at 17:43 UTC

    says perldoc -f grep

    In scalar context, returns the number of times the expression was true.
    And watch your language ;) a list evaluated in scalar context does not give its length my $len = (3,4,5); # $len == 5 ! only an array gives back its length in scalar context.

    It would be very inefficient to first build up an array with lots of elements and then only use its length. That's why only a number is returned directly.

    -- Hofmator

      I stand corrected. My bad. :)

      ------
      /me wants to be the brightest bulb in the chandelier!

      But isn't ... *pouts*