perlquestion
vagabonding electron
Dear Monks,<br>
doing some exercises from the Alpaca book I noticed a strange behavior of the grep operator.<br>
The exercise was to filter the files smaller than 1000 bytes.
<br>
This code (if called with C:\perl\bin>perl script.pl N:/TEMP/*):
<c>
#!/usr/bin/perl -l
use strict;
use warnings;
@ARGV = map{glob} @ARGV;
my @selection = grep { -s < 1000 } @ARGV;
print for @selection;
</c>
produces the following error message:
<c>
Warning: Use of "-s" without parentheses is ambiguous at script.pl line 7.
Unterminated <> operator at script.pl line 7.
</c>
If I use the parenthesis it runs ok:
<c>
#!/usr/bin/perl -l
use strict;
use warnings;
@ARGV = map{glob} @ARGV;
my @selection = grep { (-s) < 1000 } @ARGV;
print for @selection;
</c>
If I search for files bigger than 1000 the parentheses are not necessary.<br>
It seems that perl interprets the less than sign as a part of a diamond operator.<br>
In the answers part of the book however there is a line exact as my original line without parentheses:
<c>
my @smaller_than_1000 = grep { -s < 1000 } @ARGV;
</c>
Is it the windows peculiarity which I have here?<br>
Thanks in advance!<br>
VE