question about ( () if () ) while ();

From: William M West (william_west_at_reyrey.com)
Date: 08/03/04


To: beginners@perl.org
Date: Tue, 3 Aug 2004 10:16:21 -0400


$ perl -e ' $entry = "willy"; (print "1") if (/$entry/) while ($_ = "will");
print "0"'
syntax error at -e line 1, near ") while"
Execution of -e aborted due to compilation errors.

seperating the bits seems to work. it seems to break down when i want to
use the if statement in combination with the while.

using print to simulate return values.

perhaps i should abandon this idiom and use a normal

while () {
        if () {
        
        }
}

i am curious as to why this error crops up...

thanks,

willy
http://www.hackswell.com/corenth



Relevant Pages

  • error message
    ... syntax error at ./dbubdate.pl line 181, ... Execution of ./dbubdate.pl aborted due to compilation errors. ... Levente Kovacs ...
    (perl.beginners)
  • Re: Math::BigFloat oddities
    ... syntax error at -e line 1, at EOF ... Execution of -e aborted due to compilation errors. ...
    (comp.lang.perl.misc)
  • Re: Why `for local $var (LIST) ... not allowed?
    ... Todd wrote: ... syntax error at - line 3, ... Execution of - aborted due to compilation errors. ...
    (comp.lang.perl.misc)
  • Re: Program for retrieving certain lines in a file and writing them to another file
    ... I have actually been trying your suggestion and I assumed there is a ... syntax error at C:\perlstuff\sample.pl line 1, ... Execution of C:\perlstuff\sample.pl aborted due to compilation errors. ...
    (comp.lang.perl.misc)
  • Re: javascript works in IE, not in firefox
    ... And Randy is correct in stating that document.wirte does not work at all in XHTML DOMs, but that is not a factor here as the page is served to Firefox browsers with a text/html content type header so whatever the mark-up may resemble it is always being interpreted as tag soup HTML. ... The specification defines the syntax for the language, but it also allows for extensions, and for more tolerant interpretations of the syntax (this means that an ECMAScript implementation must provide everything specified by ECMA 262 but may provide more, and an implementation may elect to cope with some ECMA 262 syntax errors as if they were not errors but it is not allowed to treat anything that is valid by ECMA 262 as an error). ... It is a syntax error because the two distinct syntax units from which an ECMAScript Program is constructed are Statements and FunctionDeclarations, and as a result you cannot put a FunctionDeclarations inside a Statement. ... When javascript is executed FunctionDeclarations are acted upon prior to the execution of any Statements in the pertinent execution context. ...
    (comp.lang.javascript)