Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: The "<" in the grep block

by Athanasius (Monsignor)
on Sep 23, 2012 at 15:25 UTC ( #995211=note: print w/ replies, xml ) Need Help??


in reply to The "<" in the grep block

To reinforce tobyink’s answer:

Is it the windows peculiarity which I have here?

No, with

use strict; use warnings; use diagnostics;

I get identical messages under cmd.exe (perl 5, version 16, subversion 0 (v5.16.0) built for MSWin32-x86-multi-thread-64int) and Cygwin (perl, v5.10.1 (*) built for i686-cygwin-thread-multi-64int):

$ perl -c 298_SoPW.pl Warning: Use of "-s" without parentheses is ambiguous at 298_SoPW.pl l +ine 36 (#1) (S ambiguous) You wrote a unary operator followed by something tha +t looks like a binary operator that could also have been interpreted + as a term or unary operator. For instance, if you know that the rand function has a default argument of 1.0, and you write rand + 5; you may THINK you wrote the same thing as rand() + 5; but in actual fact, you got rand(+5); So put in parentheses to say what you really mean. Unterminated <> operator at 298_SoPW.pl line 36 (#2) (F) The lexer saw a left angle bracket in a place where it was exp +ecting a term, so it's looking for the corresponding right angle bracket, + and not finding it. Chances are you left some needed parentheses out earlier in the line, and you really meant a "less than". Uncaught exception from user code: Unterminated <> operator at 298_SoPW.pl line 36. at 298_SoPW.pl line 36
If I search for files bigger than 1000 the parentheses are not necessary.

I take it you mean:

my @selection = grep { -s > 1000 } @ARGV;

Here there is no ambiguity, since > doesn’t begin any other operator, as < does.

Update: The following excerpt from -X may also be of (tangential) interest:

These operators are exempt from the "looks like a function rule" described above. That is, an opening parenthesis after the operator does not affect how much of the following code constitutes the argument. Put the opening parentheses before the operator to separate it from code that follows (this applies only to operators with higher precedence than unary operators, of course):

-s($file) + 1024 # probably wrong; same as -s($file + 1024) (-s $file) + 1024 # correct

Hope that helps,

Athanasius <°(((><contra mundum


Comment on Re: The "<" in the grep block
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-07-26 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls