in reply to Re: Problems with grep
in thread Problems with grep

Grep returns scalars, example
D:\>perl -e"die grep /6/, 3 .. 6,6,6" 666 at -e line 1.

grep returns a list, and in scalar context, the number of elements the expression was true.

In your example, die outputs the list returned by grep:

perl -e "die scalar grep /6/, 3 .. 6,6,6" 3 at -e line 1.

What you did is essentially the same as:

perl -e 'die qw/1 2 3/' 123 at -e line 1.

citromatik

Replies are listed 'Best First'.
Re^3: Problems with grep
by Anonymous Monk on Jan 30, 2009 at 14:58 UTC
    | \|/ scalars<-- /|\ |
    perldoc -f grep is better :)

      That is not correct, as I said before grep returns a list, and that list is not restricted to be a list of scalars as you are claiming:

      update: References are scalars, sorry for the confusion

      use strict; use warnings; use Data::Dumper; my @t = ( [1,2,3], 0, [4,5,6] ); my @k = grep { ref $_ eq "ARRAY" } @t; print Dumper \@k;
      Outputs:
      531(255)[1603][/home/pignatelli/tmp]$ perl kkk.pl $VAR1 = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ];

      citromatik

        that list is not restricted to be a list of scalars

        Yes it is, as all lists are. You can't have a list of anything but scalars. In your example, grep returned two scalars, both of which are references.