You really need to show your input and output as well as the process you're using to get from one to the other. Guidelines for doing this can be found in "How do I post a question effectively?".
"but it is not working , @foo_d always holds 1 if anyone can please help out"
How are you determining what "@foo_d always holds"? Here's a number of different ways that you might be doing this:
$ perl -Mstrict -Mwarnings -le '
my @all_words = qw{abc "def ghi "jkl mno};
print "*** Using grep BLOCK LIST ***";
my @qq_words_block = grep { /^"/ } @all_words;
print "qq_words_block = ", @qq_words_block;
print "qq_words_block = " . @qq_words_block;
print "qq_words_block = ", "@qq_words_block";
print "qq_words_block = " . "@qq_words_block";
print "*** Using grep EXPR, LIST ***";
my @qq_words_expr = grep(/^"/, @all_words);
print "qq_words_expr = ", @qq_words_expr;
print "qq_words_expr = " . @qq_words_expr;
print "qq_words_expr = ", "@qq_words_expr";
print "qq_words_expr = " . "@qq_words_expr";
'
*** Using grep BLOCK LIST ***
qq_words_block = "def"jkl
qq_words_block = 2
qq_words_block = "def "jkl
qq_words_block = "def "jkl
*** Using grep EXPR, LIST ***
qq_words_expr = "def"jkl
qq_words_expr = 2
qq_words_expr = "def "jkl
qq_words_expr = "def "jkl
In list context, @array expands to its elements;
in scalar context, you get the number of elements.
Search for $LIST_SEPARATOR in perlvar for a discussion of why "@array" separates the elements with spaces.
|