[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-beginners
Subject: =?gb2312?B?tPC4tDogdGhlIHdheSB0byBnZXQgY3VycmVudCBpbmRleCBvZiBhbiBhcnI=?=
From: <zhao_bingfeng () topsec ! com ! cn>
Date: 2006-03-01 1:09:28
Message-ID: 013001c63ccc$ccdd2dc0$835fa8c0 () zhaobingfeng
[Download RAW message or body]
> -----ÓʼþÔ¼þ-----
> ·¢¼þÈË: JupiterHost.Net [mailto:mlists@jupiterhost.net]
> ·¢ËÍʱ¼ä: 2006Äê2Ô 28ÈÕ 21:54
> ÊÕ¼þÈË: beginners@perl.org
> Ö÷Ìâ: Re: the way to get current index of an array
>
>
>
> zhao_bingfeng@topsec.com.cn wrote:
> > hi, perlers,
>
> Howdy,
Thanks or your and others reply
>
> > Is there a simple way to get the current index of an array in loop
>
> yes
>
> > statement? the procondition is you cannot get this information from
> > array element. For example
> >
> > #!usr/bin/perl
> > my @arr = qw/a b c d e/;
> > for(@arr)
> > {
> > print "The No.?? element is $_\n"; }
>
> for my $idx (0 .. $#arr) {
> print "The no $idx element is $arr{$_}\n"; }
>
> my $idx = 0;
> for my $item(@arr) {
> print "The no $idx element is $item\n";
> $idx++;
> }
That's great! but in another you cannot touched context, what can we do? these
is no $ prefixed magic indicated this, but maybe some other corners keep this
info?
>
> There are other more magical ways but those will probably be
> best for you :)
>
> The first way not only has less code but is faster.
>
> HTH :)
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org For
> additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
["smime.p7s" (application/x-pkcs7-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic