vagabonding electron has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
doing some exercises from the Alpaca book I noticed a strange behavior of the grep operator.
The exercise was to filter the files smaller than 1000 bytes.
This code (if called with C:\perl\bin>perl script.pl N:/TEMP/*):
It seems that perl interprets the less than sign as a part of a diamond operator.
In the answers part of the book however there is a line exact as my original line without parentheses:
Thanks in advance!
VE
doing some exercises from the Alpaca book I noticed a strange behavior of the grep operator.
The exercise was to filter the files smaller than 1000 bytes.
This code (if called with C:\perl\bin>perl script.pl N:/TEMP/*):
produces the following error message:#!/usr/bin/perl -l use strict; use warnings; @ARGV = map{glob} @ARGV; my @selection = grep { -s < 1000 } @ARGV; print for @selection;
If I use the parenthesis it runs ok:Warning: Use of "-s" without parentheses is ambiguous at script.pl lin +e 7. Unterminated <> operator at script.pl line 7.
If I search for files bigger than 1000 the parentheses are not necessary.#!/usr/bin/perl -l use strict; use warnings; @ARGV = map{glob} @ARGV; my @selection = grep { (-s) < 1000 } @ARGV; print for @selection;
It seems that perl interprets the less than sign as a part of a diamond operator.
In the answers part of the book however there is a line exact as my original line without parentheses:
Is it the windows peculiarity which I have here?my @smaller_than_1000 = grep { -s < 1000 } @ARGV;
Thanks in advance!
VE
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: The "<" in the grep block
by tobyink (Canon) on Sep 23, 2012 at 15:12 UTC | |
Re: The "<" in the grep block
by Athanasius (Archbishop) on Sep 23, 2012 at 15:25 UTC | |
Re: The "<" in the grep block
by NetWallah (Canon) on Sep 23, 2012 at 15:15 UTC | |
Re: The "<" in the grep block
by Marshall (Canon) on Sep 23, 2012 at 16:36 UTC | |
by BrowserUk (Patriarch) on Sep 23, 2012 at 17:10 UTC | |
by vagabonding electron (Curate) on Sep 23, 2012 at 17:15 UTC | |
by 2teez (Vicar) on Sep 23, 2012 at 18:17 UTC | |
by BrowserUk (Patriarch) on Sep 23, 2012 at 18:24 UTC | |
by Anonymous Monk on Sep 23, 2012 at 22:26 UTC | |
Re: The "<" in the grep block
by vagabonding electron (Curate) on Sep 23, 2012 at 17:27 UTC |
Back to
Seekers of Perl Wisdom