http://www.perlmonks.org?node_id=743657


in reply to Re: For vs. Foreach
in thread For vs. Foreach

Peeking in toke.c suggests there is one difference between 'for' and 'foreach'. It seems it's valid to use 'for' somewhere in an attribute declaration. The documentation about attribute doesn't make it clear to me how. Best thing I can do is generating different error message when using 'for' or 'foreach':
$ perl -wE 'sub foo: foreach' Invalid CODE attribute: foreach at -e line 1 BEGIN failed--compilation aborted at -e line 1. $ perl -wE 'sub foo: for' syntax error at -e line 1, next token ??? Execution of -e aborted due to compilation errors.
Using 'for' is a compile time error, using 'foreach' a run time error (resulting in abortion of the compilation).

If someone could show how to use 'for' inside an attribute, that would be dandy.