Stephen Gran on 26 Nov 2003 18:58:53 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Why can't an array element be used as the index var in foreach?


On Wed, Nov 26, 2003 at 03:47:45PM -0500, Chip Salzenberg said:
> According to David Steuber:
> > Ok, I typed it in again and it worked just fine using the C style for.
> > I guess I flubbed something and was just not paying attention as to
> > what.
> 
> <mjd> THE ERROR MESSAGE!  READ THE ERROR MESSAGE!! </mjd>

steve:~$ perl -wle 'for ($c[0] = 0; $c[0] < 5; $c[0]++;){print $c[0];}'
syntax error at -e line 1, near "++;"
Execution of -e aborted due to compilation errors.
steve:~$ perl -wle "for ($c[0] = 0; $c[0] < 5; $c[0]++;){print $c[0];}"
Can't modify single ref constructor in scalar assignment at -e line 1, near "0;"
syntax error at -e line 1, near "++;"
Execution of -e aborted due to compilation errors.

I tried it with both quoting styles in case the shell was somehow
interfering.

steve:~$ dpkg -l perl
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                      Version                   Description
+++-=========================-=========================-==================================================================
ii  perl                      5.8.2-2                   Larry Wall's Practical Extraction and Report Language.

Odd.

-- 
 --------------------------------------------------------------------------
|  Stephen Gran                  | I try to keep an open mind, but not so  |
|  steve@lobefin.net             | open that my brains fall out.   --      |
|  http://www.lobefin.net/~steve | Judge Harold T. Stone                   |
 --------------------------------------------------------------------------

Attachment: pgpiD3Vny7dpC.pgp
Description: PGP signature