in reply to postincrement bug(?) in for
In your first example, perl is parsing $i as being a filehandle where output should be directed, which then makes the ++ operator the output which should be printed there. But print ++ for 1 is not valid, producing the syntax error you received:
$ perl -e 'print ++ for 1' syntax error at -e line 1, near "++ for "
In the second example, $i++ is unambiguous, because you can't increment a filehandle.
|
|---|