On Fri, 20 Jan 2012 10:08:31 +0600, Andrey P wrote: > 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*...
Because grep is defined to return the number of elements in scalar context. Keep reading perldoc -f grep one more sentence: In scalar context, returns the number of times the expression was true. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 http://www.oreillyschool.com/certificates/perl-programming.php -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/