Perl / perl5

đŸȘ The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

perl parse not parsing post-position 'for(;;)' as camel claims #12751

Closed p5pRT closed 11 years ago

p5pRT commented 11 years ago

Migrated from rt.perl.org#116605 (status was 'rejected')

Searchable as RT116605$

p5pRT commented 11 years ago

From perl-diddler@tlinx.org

Created by perl-diddler@tlinx.org

I classified this as 'medium' (not high or critical)\, as it is obviously a corner case in the parser.

I had​: perl -E ' use P; for ($_=3;$_-- >0;) { P "_=%s"\, $_ }'
_=2 _=1 _=0 --- Decided to try the post-fix notation​: perl -E ' use P; P "_=%s"\, $_ for $_=3;$_-- >0; ' _=3 --- Warnings would have pointed out​: Useless use of numeric gt (>) in void context at -e line 1.

I tried it with parens​:

perl -E ' use P; P "_=%s"\, $_ for ($_=3;$_-- >0;) ' syntax error at -e line 3\, near "3;" syntax error at -e line 3\, near ";) " Execution of -e aborted due to compilation errors.

(Note\, to reproduce this without P​: perl -lE' print sprintf "_%s"\, $_ for $_=3;$_-- >0; '

- I generally prefer to save on typing)...

--- Now some said that in the postfix notation\, the for was interpreted as a synonym for "foreach".

As I was quoted on perlmonks​:

From the Camel Book (4th Edition\, 2012\, page 142)​:

  For historical reasons\, the foreach keyword is a synonym for the for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my.   **** (Don’t worry—Perl can easily distinguish for (@​ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***

----- The '****' are mine. Note that perl is supposed to be able to distinguish my usage of "for my $_=0; $_--\<0;[;]" due to the extra semicolons.

(I originally had a double semi at the end\, and figured that was clearly redundant)

Perl know's something is wrong in the warnings... it sees the incorrect syntax.

Even with parens\, when it really has the hint of semicolons in a for(;;)\, the Camel book claims it *should* know the difference...

  I only gave this as high as a 'medium' because\, it so clearly goes against the wording of the 'camel'... though\, admittedly\, it is the first time i've run into this corner case (trying to make code "more brief" and more efficient" -- and read that entering a loop has a context overhead whereas the post-fix format of the loop did not). Dunno if it is true It's in the comments of Exporter.pm\, which I was trying to 'grok'\, chasing down an obscure bug...

  I didn't know "for(;;)" was a lone exception to the post-fix notation\, and think\, given the camel book\, it's clearly an oversight in consistency.

Perl Info ``` Flags: category=core severity=medium This perlbug was built using Perl 5.16.1 - Mon Sep 10 13:51:31 UTC 2012 It is being executed now by Perl 5.16.1 - Mon Sep 10 13:45:59 UTC 2012. Site configuration information for perl 5.16.1: Configured by abuild at Mon Sep 10 13:45:59 UTC 2012. Summary of my perl5 (revision 5 version 16 subversion 1) configuration: Platform: osname=linux, osvers=3.4.6-2.10-default, archname=x86_64-linux-thread-multi uname='linux build35 3.4.6-2.10-default #1 smp thu jul 26 09:36:26 utc 2012 (641c197) x86_64 x86_64 x86_64 gnulinux ' config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Dd_dbm_open -Duseshrplib=true -Doptimize=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -Accflags=-DPERL_USE_SAFE_PUTENV -Dotherlibdirs=/usr/lib/perl5/site_perl' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe', cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -fstack-protector' ccversion='', gccversion='4.7.1 20120723 [gcc-4_7-branch revision 189773]', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib64 -fstack-protector' libpth=/lib64 /usr/lib64 /usr/local/lib64 libs=-lm -ldl -lcrypt -lpthread perllibs=-lm -ldl -lcrypt -lpthread libc=/lib64/libc-2.16.so, so=so, useshrplib=true, libperl=libperl.so gnulibc_version='2.16' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.16.1/x86_64-linux-thread-multi/CORE' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64 -fstack-protector' Locally applied patches: @INC for perl 5.16.1: /home/law/bin/lib /usr/lib/perl5/site_perl/5.16.1/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.16.1 /usr/lib/perl5/vendor_perl/5.16.1/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.16.1 /usr/lib/perl5/5.16.1/x86_64-linux-thread-multi /usr/lib/perl5/5.16.1 /usr/lib/perl5/site_perl/5.16.1/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.16.1 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.16.0/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.16.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/site_perl . Environment for perl 5.16.1: HOME=/home/law LANG=en_US.UTF-8 LANGUAGE (unset) LC_COLLATE=C LC_CTYPE=en_US.UTF-8 LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=.:/sbin:/usr/local/sbin:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/dell/srvadmin/bin:/usr/sbin:/etc/local/func_lib:/home/law/lib:/home/law/bin/lib PERL5OPT=-CSA -I/home/law/bin/lib PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 11 years ago

From @arc

Linda Walsh \perlbug\-followup@&#8203;perl\.org wrote​:

Now some said that in the postfix notation\, the for was interpreted as a synonym for "foreach".

That doesn't match the Perl documentation; `perldoc perlsyn` has this to say about statement modifiers​:

Any simple statement may optionally be followed by a SINGLE modifier\, just before the terminating semicolon (or block ending). The possible modifiers are​:

if EXPR
unless EXPR
while EXPR
until EXPR
for LIST
foreach LIST
when EXPR

That doesn't include anything like "for (EXPR; EXPR; EXPR)".

From the Camel Book (4th Edition\, 2012\, page 142)​:

For historical reasons\, the foreach keyword is a synonym for the for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation\. We tend to prefer for because we are lazy and because it is more readable\, especially with the my\.
\*\*\*\* \(Don’t worry—Perl can easily distinguish for \(@&#8203;ARGV\) from for \($i=0; $i\<$\#ARGV; $i\+\+\) because the latter contains semicolons\.\) \*\*\*

The Camel book isn't something that p5p has any control over.

I've had an (admittedly brief) look at Perl's documentation for "for" and "foreach"\, and I can't see anything which might be construed as suggesting that three-part "for" can be used as a statement modifier. If you can point to anything I've missed\, please let us know\, and we can clarify those parts of the documentation.

Thanks.

-- Aaron Crane ** http​://aaroncrane.co.uk/

p5pRT commented 11 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 11 years ago

From @ilmari

Linda Walsh (via RT) \perlbug\-followup@&#8203;perl\.org writes​:

Decided to try the post-fix notation​: perl -E ' use P; P "_=%s"\, $_ for $_=3;$_-- >0; ' _=3 --- Warnings would have pointed out​: Useless use of numeric gt (>) in void context at -e line 1.

Note that L\<perlsyn/Statment Modifiers>Âč only lists "for LIST" and "foreach LIST".

The (EXPR; EXPR; EXPR) form is only listed in L\<perlsyn/Compound Statements>ÂČ.

[1] https://metacpan.org/module/perlsyn#Statement-Modifiers [2] https://metacpan.org/module/perlsyn#Compound-Statements

As I was quoted on perlmonks​:

From the Camel Book (4th Edition\, 2012\, page 142)​:

For historical reasons\, the foreach keyword is a synonym for the for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation\. We tend to prefer for because we are lazy and because it is more readable\, especially with the my\. 
\*\*\*\* \(Don’t worry—Perl can easily distinguish for \(@&#8203;ARGV\) from for \($i=0; $i\<$\#ARGV; $i\+\+\) because the latter contains semicolons\.\) \*\*\*

Is this in a section on compound statements\, or about statement modifiers? They are not the same\, despite having similar (but not identical!) names and behavoiur.

-- "A disappointingly low fraction of the human race is\, at any given time\, on fire." - Stig Sandbeck Mathisen

p5pRT commented 11 years ago

From Eirik-Berg.Hanssen@allverden.no

On Fri\, Feb 1\, 2013 at 11​:40 AM\, Aaron Crane \perl@&#8203;aaroncrane\.co\.uk wrote​:

From the Camel Book (4th Edition\, 2012\, page 142)​:

For historical reasons\, the foreach keyword is a synonym for the for

keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my. **** (Don’t worry—Perl can easily distinguish for (@​ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***

The Camel book isn't something that p5p has any control over.

  Nor is it entirely wrong. It is technically correct\, which\, as I was recently told\, is the best kind of correct.

  Yes\, the keywords are synonymous\, and can be used interchangeably\, even as statement modifiers​:

$ perl -E 'say foreach 1..3' 1 2 3 $

  And yes\, Perl "can easily distinguish for (@​ARGV) from for ($i=0; $i\<$#ARGV; $i++)"\, and does so\, even for statement modifiers. Quite distinct results​:

$ perl -E 'say for (@​ARGV)' 1 2 3 1 2 3 $ perl -E 'say for ($i=0; $i\<$#ARGV; $i++)' 1 2 3 syntax error at -e line 1\, near "0;" syntax error at -e line 1\, near "++) " Execution of -e aborted due to compilation errors. $

  And no\, it does not say that the C\<\< for (EXPR; EXPR; EXPR) >> construct (or foreach equivalent) is accepted as a statement modifier.

  Not technically\, anyway. ;-)

Eirik

p5pRT commented 11 years ago

@iabyn - Status changed from 'open' to 'rejected'

p5pRT commented 11 years ago

From @ikegami

On Fri\, Feb 1\, 2013 at 3​:15 AM\, Linda Walsh \perlbug\-followup@&#8203;perl\.orgwrote​:

From the Camel Book (4th Edition\, 2012\, page 142)​:

For historical reasons\, the foreach keyword is a synonym for the for

keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my. **** (Don’t worry—Perl can easily distinguish for (@​ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***

The part outside the stars is correct.   foo() for (1;2;3); and   foo() foreach (1;2;3); are equivalent.

The part inside the stars is also correct. It's easy to distinguish   for (@​ARGC) from   ($i=0; $i\<$#ARGV; $i++)

That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.

- Eric

p5pRT commented 11 years ago

From perl-diddler@tlinx.org

On Fri Feb 01 02​:41​:52 2013\, perl@​aaroncrane.co.uk wrote​:

Linda Walsh \perlbug\-followup@&#8203;perl\.org wrote​:

Now some said that in the postfix notation\, the for was interpreted as a synonym for "foreach".

That doesn't match the Perl documentation; `perldoc perlsyn` has this to say about statement modifiers​:

Any simple statement may optionally be followed by a SINGLE modifier\, just before the terminating semicolon (or block ending). The possible modifiers are​:

if EXPR
unless EXPR
while EXPR
until EXPR
for LIST
foreach LIST
when EXPR

That doesn't include anything like "for (EXPR; EXPR; EXPR)".

From the Camel Book (4th Edition\, 2012\, page 142)​:

For historical reasons\, the foreach keyword is a synonym for the

for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my. **** (Don’t worry—Perl can easily distinguish for (@​ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***

The Camel book isn't something that p5p has any control over.

I've had an (admittedly brief) look at Perl's documentation for "for" and "foreach"\, and I can't see anything which might be construed as suggesting that three-part "for" can be used as a statement modifier. If you can point to anything I've missed\, please let us know\, and we can clarify those parts of the documentation.

Thanks.

====================================================================

No wonder people close out my bugs claiming there is no response...

People need to get a clue... if my responses are being censored\, you can't expect reply unless I checked (as i did this time -- as I thought it odd I got no response nor notice that the bug had been closed.

-------- Original Message -------- Subject​: Re​: [perl #116605] perl parse not parsing post-position 'for(;;)' as camel claims Date​: Fri\, 01 Feb 2013 07​:00​:25 -0800 From​: Linda W \perl\-diddler@&#8203;tlinx\.org To​: perlbug-followup@​perl.org References​: \RT\-Ticket\-116605@&#8203;perl\.org \5\.16\.1\_13583\_1359704903@&#8203;Ishtar\.sc\.tlinx\.org \rt\-3\.6\.HEAD\-27190\-1359706523\-1193\.116605\-75\-0@&#8203;perl\.org \CACmk\_tsRX=Ukz0WBx9qf=peK2\+\-\-1TETkc=rawm\-3r3e\-2o4yg@&#8203;mail\.gmail\.com \rt\-3\.6\.HEAD\-27190\-1359715312\-1576\.116605\-94\-0@&#8203;perl\.org

Aaron Crane via RT wrote​:

Any simple statement may optionally be followed by a SINGLE modifier\, just before the terminating semicolon (or block ending). The possible modifiers are​:

if EXPR
unless EXPR
while EXPR
until EXPR
for LIST
foreach LIST
when EXPR

  What statements that control modifiers besides 'for' Cannot follow as post-fix operators?

  More concern to me is 'regularity' in the language. I may very easily be overlooking the obvious\, but it seems like "for(;;)" stands alone as the single flow control statement that can't be used in post-fix form.

  Someone read to me the what felt like an obvious statement -- that perl can tell the difference in the forms and doesn't confuse the for(;;) (with semicolons) with the for(LIST). So it made no sense that for(;;) (that perl would never confuse with for(LIST)\, wouldn't be supported as a special case.

  Is there a special reason why it cannot or should not be supported the same as the other control statements and why a "special case" for it "not working" the way the rest do\, be adhered to? I really don't know -- honest... it just seems out of place\, like a wart....

;-)

p5pRT commented 11 years ago

perl-diddler@tlinx.org - Status changed from 'rejected' to 'open'

p5pRT commented 11 years ago

From perl-diddler@tlinx.org

-------- Original Message -------- Subject​: Re​: [perl #116605] perl parse not parsing post-position 'for(;;)' as camel claims Date​: Fri\, 01 Feb 2013 13​:46​:48 -0800 From​: Linda W \perl\-diddler@&#8203;tlinx\.org To​: perlbug-followup@​perl.org References​: \RT\-Ticket\-116605@&#8203;perl\.org \5\.16\.1\_13583\_1359704903@&#8203;Ishtar\.sc\.tlinx\.org \rt\-3\.6\.HEAD\-27190\-1359706523\-1193\.116605\-75\-0@&#8203;perl\.org \CALJW\-qGfgzTj0xzRGHAKg2qqhJgKjS\+SpR2gUO5uf2qGWhSL5w@&#8203;mail\.gmail\.com \rt\-3\.6\.HEAD\-27190\-1359743084\-1098\.116605\-94\-0@&#8203;perl\.org

On Fri Feb 01 10​:24​:44 2013\, ikegami@​adaelis.com wrote​:

That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.

- Eric

Nor does it claim that it does not. It says not to worry about use of "for(;;)"\, as "Perl can easily distinguish" between the two usages.

  That implies that "for(;;)"\, could be used in any place "foreach" can be used and for the user NOT to WORRY\, as Perl can easily distinguish between the two.

I asked what other start-of-flow control words besides for(;;) could not be used in a postfix manner. If "for(;;)" is the only one -- why? Since perl can parse it the same as any other\, why should it be the 1 control statement that it shouldn't parse -- just because you want to be able to point fingers at people\, post "LOL" comments (on PM)\, and tell people it is there bug?

How childish is that? I get kicked from the list for telling someone that those who don't change -- like the dinosaurs\, end up having problems (there was nothing personally attacking in my post\, Ricardo just didn't like being told the world was round​: it was flat\, by original design\, and would be kept that way for compatibility with previous design. ;^/

It is a non-regularity in the language that doesn't need to be there. It would follow that if one thought all of the other flow-control words could be post-fixed\, then why not that one? I don't need "it's your bug" as a reason -- that's Certainly it is not rational\, technical nor compelling compelling reason why irregularities in the language shouldn't be fixed when possible (even though it is rather consistent with the reasoning[sic] why I was no longer allowed to post to the flock of believers...

That perl has so many exceptions works against it. It's a major reason why\, like python's founder\, Larry thought a complete overhaul was necessary -- because people wouldn't accept piecemeal improvements.

While the ability to "deprecate" bad design and features has improved\, grandfather logic has dominated the p5p list to the point that those pushing for change are eliminated from the list -- even when it is a something so trivial as regularizing the documentation!

p5pRT commented 11 years ago

From @jkeenan

On Sat Feb 02 18​:30​:18 2013\, LAWalsh wrote​:

-------- Original Message -------- Subject​: Re​: [perl #116605] perl parse not parsing post-position 'for(;;)' as camel claims Date​: Fri\, 01 Feb 2013 13​:46​:48 -0800 From​: Linda W \perl\-diddler@&#8203;tlinx\.org To​: perlbug-followup@​perl.org References​: \RT\-Ticket\-116605@&#8203;perl\.org \5\.16\.1\_13583\_1359704903@&#8203;Ishtar\.sc\.tlinx\.org \rt\-3\.6\.HEAD\-27190\-1359706523\-1193\.116605\-75\-0@&#8203;perl\.org \CALJW\-qGfgzTj0xzRGHAKg2qqhJgKjS\+SpR2gUO5uf2qGWhSL5w@&#8203;mail\.gmail\.com \rt\-3\.6\.HEAD\-27190\-1359743084\-1098\.116605\-94\-0@&#8203;perl\.org

On Fri Feb 01 10​:24​:44 2013\, ikegami@​adaelis.com wrote​:

That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.

- Eric

Nor does it claim that it does not. It says not to worry about use of "for(;;)"\, as "Perl can easily distinguish" between the two usages.

That implies that "for\(;;\)"\, could be used in any place

"foreach" can be used and for the user NOT to WORRY\, as Perl can easily distinguish between the two.

I asked what other start-of-flow control words besides for(;;) could not be used in a postfix manner. If "for(;;)" is the only one -- why? Since perl can parse it the same as any other\, why should it be the 1 control statement that it shouldn't parse -- just because you want to be able to point fingers at people\, post "LOL" comments (on PM)\, and tell people it is there bug?

How childish is that? I get kicked from the list for telling someone that those who don't change -- like the dinosaurs\, end up having problems (there was nothing personally attacking in my post\, Ricardo just didn't like being told the world was round​: it was flat\, by original design\, and would be kept that way for compatibility with previous design. ;^/

It is a non-regularity in the language that doesn't need to be there. It would follow that if one thought all of the other flow-control words could be post-fixed\, then why not that one? I don't need "it's your bug" as a reason -- that's Certainly it is not rational\, technical nor compelling compelling reason why irregularities in the language shouldn't be fixed when possible (even though it is rather consistent with the reasoning[sic] why I was no longer allowed to post to the flock of believers...

That perl has so many exceptions works against it. It's a major reason why\, like python's founder\, Larry thought a complete overhaul was necessary -- because people wouldn't accept piecemeal improvements.

While the ability to "deprecate" bad design and features has improved\, grandfather logic has dominated the p5p list to the point that those pushing for change are eliminated from the list -- even when it is a something so trivial as regularizing the documentation!

The responses to the OP sufficiently address the issue raised. If the OP wants to pursue the issue\, she can submit a patch.

Closing ticket.

Thank you very much. Jim Keenan

p5pRT commented 11 years ago

@jkeenan - Status changed from 'open' to 'rejected'

p5pRT commented 11 years ago

From @ikegami

On Sat\, Feb 2\, 2013 at 9​:30 PM\, Linda Walsh via RT \< perlbug-followup@​perl.org> wrote​:

On Fri Feb 01 10​:24​:44 2013\, ikegami@​adaelis.com wrote​:

That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.

- Eric

Nor does it claim that it does not. It says not to worry about use of "for(;;)"\, as "Perl can easily distinguish" between the two usages.

And it does. No C\<for (LIST)> was created. So even though the book is surely talking about flow control statements\, what it says is also true when you misapply it to statement modifiers.

I asked what other start-of-flow control words besides for(;;) could not

be used in a postfix manner.

Actually\, no you didn't. You filed a bug report because Perl "so clearly goes against the wording of the 'camel'." (That wouldn't be a Perl bug even if it was true!)

If you had asked that\, I would have pointed out that you're being too lazy to try it yourself or read the docs yourself.

If "for(;;)" is the only one -- why?

For starters\, it's impossible. It can't be added for consistency without still being inconsistent.

C\<while (EXPR) BLOCK> has a corresponding C\<EXPR while EXPR;>. ... C\<for (LIST) BLOCK> has a corresponding C\<EXPR for LIST;>. C\<for (EXPR;EXPR;EXPR) BLOCK> cannot have a corresponding C\<EXPR for EXPR; EXPR; EXPR;> because that would be three statements.

Secondly\, it would be next to useless . The most common usage of for(;;) is

for (my $x = 0; $x\<10; ++$x) { f($x); }

But that couldn't be written

f($x) for (my $x = 0; $x\<10; ++$x);

It would have to be written

{ my $x; f($x) for ($x = 0; $x\<10; ++$x); }

At this point\, you might as well use something else.