Ask a Question related to PERL Miscellaneous, Design and Development.
-
Clyde Ingram #1
Inconsistent behaviour of empty "while" EXPR
Odd one this:an empty EXPRession in a "while" loop seems to take a defined
value in this call from either ksh on solaris 2.6 to Perl 5.004, or Cygwin
on Win2k or Win98 to Perl 5.8.0 (ActiveState binary 806):
perl -e 'while () { print "Aha "; }'
because it loops endlessly, printing "Aha Aha Aha Aha . . .".
Same behaviour if I beef this up into:
perl -wTe 'use strict; while () { print "Aha "; }'
or even it I put this into a file (fred), make it executable (chmod 755
fred), and run it (perl fred).
Contrast this with:
perl -e 'do { print "Aha "; } while ();'
which only prints "Aha " once, and then stops.
Contrast still further with:
perl -e 'if () { print "Aha "; }'
which fails with:
syntax error at -e line 1, near "() "
Execution of -e aborted due to compilation errors.
Note also, these print nothing, as expected:
perl -e 'while (undef) { print "Aha "; }'
perl -e 'while ("") { print "Aha "; }'
perl -e 'while (0) { print "Aha "; }'
perl -e 'while (defined) { print "Aha "; }'
Now the Perl manual says:
if (EXPR) BLOCK
. . .
LABEL while (EXPR) BLOCK
. . .
The while statement executes the block as long as the expression is
true (does not evaluate to the null string "" or 0 or "0").
Can anyone explain why my very first "while ()" looped endlessly, but the
"do . . . while ()" stopped?
And should I be surprised that the "if ()" gave a syntax error instead?
Thank-you,
Clyde
Clyde Ingram Guest
-
Setting "URL Behaviour" to "Dynamic" has no effect
Greetings When I set the "URL Behaviour" of a web reference an entry is created in the "Web.config", but the value in the "Web Reference URL"... -
Servervariables("logon_user") returns empty string
Hi, Is the Anonymous access trued off in IIS? JN NSQUARED2 -
Problem with DataGrid and values that are empty when AutoGenerateColumns="False"
Hi! Im currently writing my Master Thesis in Computer Science and i have get caught in a strange DataGrid problem. Im using a DataGrid with 4... -
inconsistent "invalid library" message
Hi, I have compiled a dynamic loaded PHP module and sometimes I get a "invalid library (maybe not a PHP library)" message. I just have to... -
"Start" "Program" "Menu" list is empty
For what ever reason my list of installed programs in my "Start" "Programs" menu is empty. Anyone know how to restore the list. Thanks for your... -
Abigail #2
Re: Inconsistent behaviour of empty "while" EXPR
Clyde Ingram
(clyde@nohamorspamgetofftheline.freeservenohamorsp am.co.uk.nohamorspam) wrote on MMMDCLXVII September MCMXCIII in <URL:news:3Jq9b.2166$966.1671@newsfep3-gui.server.ntli.net>:
?? Odd one this:an empty EXPRession in a "while" loop seems to take a defined
?? value in this call from either ksh on solaris 2.6 to Perl 5.004, or Cygwin
?? on Win2k or Win98 to Perl 5.8.0 (ActiveState binary 806):
??
?? perl -e 'while () { print "Aha "; }'
??
?? because it loops endlessly, printing "Aha Aha Aha Aha . . .".
Yes. That's a feature (but poorly documented):
$ perl -MO=Deparse -e 'while () {}'
while (1) {
;
}
-e syntax OK
Here's another, similar trick:
$ perl -MO=Deparse -e 'for (;;) {}'
while (1) {
;
}
-e syntax OK
The latter trick comes from C.
?? Contrast this with:
??
?? perl -e 'do { print "Aha "; } while ();'
??
?? which only prints "Aha " once, and then stops.
?? Contrast still further with:
??
?? perl -e 'if () { print "Aha "; }'
??
?? which fails with:
??
?? syntax error at -e line 1, near "() "
?? Execution of -e aborted due to compilation errors.
Only while () BLOCK is special. Not if () BLOCK, not do BLOCK while (),
and neither EXPR while ().
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54";
print if s/<<EOT/<<EOT/e;
Just another Perl Hacker
EOT
Abigail Guest



Reply With Quote

