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..).

Regards,


-- 
Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bambams.ca/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to