develooper Front page | perl.beginners | Postings from January 2012

Difference between <> and grep EXPR, <>

Thread Next
From:
Andrey P
Date:
January 19, 2012 20:08
Subject:
Difference between <> and grep EXPR, <>
Message ID:
CAGnEzfWu_aAEkKPzTfmNbfQn-LmsDmkTVQss5nnq0VA7Z4VHsQ@mail.gmail.com
Hi!

I don't understand why I need to use a list assignment for

  say  scalar(()=<$fh>);

but not for

  say  scalar(grep /./, <$fh>);

From perlop:

If a <FILEHANDLE> is used in a context that is looking for a list, *a
list* comprising all input lines *is returned*, one line per list
element.

From perlfunc:

grep EXPR, LIST

Evaluates the BLOCK or EXPR for each element of LIST (locally setting
$_ to each element) and *returns the list value*...

Thank you,
Andrey

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About