in reply to Problems with grep

# works up to here - grep outputs a string, right? But when I get to t +he next line, I get the scalar/count output...
Grep returns scalars, example
D:\>perl -e"die grep /6/, 3 .. 6,6,6" 666 at -e line 1.
your problem is you're misusing split, example
D:\>perl -e"die split 1, 121314" 234 at -e line 1. D:\>perl -e"die split 1, 121314, 1" 121314 at -e line 1. D:\>perl -e"die split 1, 121314, 2" 21314 at -e line 1. D:\>perl -e"die split 1, 121314, 3" 2314 at -e line 1. D:\>perl -e"die split 1, 121314, 4"
you may have intended
my @matched_cve = map { split(',', $_) } @matched;

Replies are listed 'Best First'.
Re^2: Problems with grep
by citromatik (Curate) on Jan 30, 2009 at 14:36 UTC
    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

      | \|/ 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

Re^2: Problems with grep
by spstansbury (Monk) on Jan 30, 2009 at 14:59 UTC
    I knew that I was misusing something!

    Thanks for your help...

    As a brand new member, I can only say that I am astounded by the support here. The timeliness and helpfulness of the responses is incredible! Thank you all again!

    Scott...

      Welcome. “Come, friend, and do likewise.”