On Fri, Jan 9, 2015 at 10:31 AM, Brandon McCaig <bamcc...@gmail.com> wrote: > Charles: > > On Fri, Jan 9, 2015 at 12:46 PM, Charles DeRykus <dery...@gmail.com> wrote: >> On Fri, Jan 9, 2015 at 3:39 AM, Dermot <paik...@gmail.com> wrote: >>> I think John has answered your immediate question. >>> >>> ... >>> for (0..$#files) { >>> print "$_) $files[$_]\n"; >>> } >>> >> >> Alternatively (at least since 5.14) : >> >> >> say "$k) $v" while ($k,$v) = each @files; > > perldoc -f each said: > *snip* >> When called in list context, returns a 2-element list >> consisting of the key and value for the next element of a hash, >> or the index and value for the next element of an array, so >> that you can iterate over it. > *snip* >> Starting with Perl 5.14, "each" can take a scalar EXPR, which >> must hold reference to an unblessed hash or array. The >> argument will be dereferenced automatically. This aspect of >> "each" is considered highly experimental. The exact behaviour >> may change in a future version of Perl. >> >> while (($key,$value) = each $hashref) { ... } >> >> See also "keys", "values", and "sort". > > Your usage should not depend on 5.14. > > Starting with 5.14, the EXPR passed to each() can be a reference to an > array or hash instead of the data structure themselves, which will be > automatically dereferenced. I believe that is the only bit of the > functionality that is dependent on Perl 5.14 (and as of 5.14, the > automatic dereference was considered experimental; my Cygwin > environment is still back on 5.14..). >
Definitely needs a 'use 5.014' if you want to dabble. I had forgotten that it was experimental although, since it's been available for some time, I suspect it will follow the regex embedded code pathway to legitimacy, "in use for years before they dropped the 'experimental' ". Apparently undocumented that you don't need a reference either since while(($key,$value) = each @array works as well as 'each \@array'. -- Charles -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/