Mark Dominus on 25 Nov 2003 14:23:59 -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?


David Steuber <david.steuber@verizon.net>:
> I even tried the more verbose 'for ($c[0] = 0; $c[0] < 5; $c[0]++)' with
> no success.  Perl would have none of it.

No?  I don't understand why not.  The three expressions in a 'for'
loop are supposed to be completely unconstrainted.  Also, it worked
when I tried it.


        for ($c[0] = 0; $c[0] < 3; $c[0]++) {
          for ($c[1] = $c[0]; $c[1] < 3; $c[1]++) {
            for ($c[2] = $c[1]; $c[2] < 3; $c[2]++) {
              for ($c[3] = $c[2]; $c[3] < 3; $c[3]++) {
                print "@c\n";
              }
            }
          }
        }


        0 0 0 0
        0 0 0 1
        0 0 0 2
        0 0 1 1
        0 0 1 2
        0 0 2 2
        0 1 1 1
        0 1 1 2
        0 1 2 2
        0 2 2 2
        1 1 1 1
        1 1 1 2
        1 1 2 2
        1 2 2 2
        2 2 2 2
-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**