Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Using non-scalar constructs in foreach loopsby periapt (Hermit) |
on Mar 17, 2005 at 14:35 UTC ( [id://440380]=perlquestion: print w/replies, xml ) | Need Help?? |
periapt has asked for the wisdom of the Perl Monks concerning the following question:
While working a problem this morning I came across a possible solution that involved assigning sequential values to an array element, doing something and then incrementing the value and doing it again. I wondered if such a think could be done using a foreach loop without a secondary assignment; Based on my reading, I don't believe that what I want can be done. The foreach construct requires simple scalar variables. That being said, has anyone done it? For example, a typical solution might be ... This got me thinking, could I use the array elt itself. The foreach construct doesn't allow a array directly, so how about a referece/dereference ... something like Just a couple of thoughts on a rainy Thursday morning By the way, I know I can use the three arg for construct for this. I'm just trying to push the boundary of the foreach construct a little PJ use strict; use warnings; use diagnostics;
Back to
Seekers of Perl Wisdom
|
|