in reply to The "<" in the grep block
Certain Perl built-ins, including -s can take an argument or operate on the default variable $_. For example, defined $var versus just defined.
In certain circumstances, perl needs a little help to disambiguate. In this case, it's not sure whether you mean an ill-formed glob:
-s(<1000)
or
(-s) < 1000
perl could theoretically look ahead searching for a ">" to disambiguate, but IIRC it only ever looks ahead one token.
Other ways to disambiguate would be to use a different operator which suffers from fewer ambiguities:
grep { 1000 > -s } @ARGV; # or grep { -s <= 999 } @ARGV;
or to place parentheses like this:
-s() < 1000
or include an explicit $_:
-s $_ < 1000
This is not Windows specific. It could theoretically change between Perl releases, but the oldest and newest versions of Perl I have available on this computer (5.8.9 and 5.16.0) both behave the same with regard to this particular example. So I don't know why your book contains the bad example; perhaps the writer never actually tested it?
|
|---|