Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

question about ( () if () ) while ();
$ 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


Report this thread to moderator Post Follow-up to this message
Old Post
William M West
08-03-04 08:57 PM


Re: question about ( () if () ) while ();
On Aug 3, West, William M said:

>$ 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.

Check 'perldoc perlsyn'.  It explains that the "statement modifiers",
things like '... if CONDITION' and '... while CONDITION' are only allowed
after *simple* statements -- what they really should say is "expressions".

You're allowed to write

print 1 if /willy/;

because 'print 1' is an expression.  You can't write

print 1 if /willy/ while <FILE>;

because 'print 1 if /willy' is not an expression, it's a statement.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart


Report this thread to moderator Post Follow-up to this message
Old Post
Jeff 'Japhy' Pinyan
08-03-04 08:57 PM


RE: question about ( () if () ) while ();

>Check 'perldoc perlsyn'.  It explains that the "statement modifiers",
>things like '... if CONDITION' and '... while CONDITION' are only allowed
>after *simple* statements -- what they really should say is "expressions".
>
>You're allowed to write
>
>  print 1 if /willy/;
>
>because 'print 1' is an expression.  You can't write
>
>  print 1 if /willy/ while <FILE>;
>
>because 'print 1 if /willy' is not an expression, it's a statement.
>

well, this restriction has forced me to come up with:

perl -e ' $entry = "willy"; (print /$entry/) while ($_ = "wil"); print "0"'


in this test it ends up not getting to print "0", but with a match it works
great :)   i can apply it properly now when substituting a filehandle for
the expression in the while.


thank you!

>--
>Jeff "japhy" Pinyan         %  How can we ever be the sold short or
>RPI Acacia Brother #734     %  the cheated, we who for every service
>http://japhy.perlmonk.org/  %  have long ago been overpaid?
>http://www.perlmonks.org/   %    -- Meister Eckhart

Report this thread to moderator Post Follow-up to this message
Old Post
William M West
08-03-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:36 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.