develooper Front page | perl.beginners | Postings from February 2002

RE: iteration default variable

Thread Previous | Thread Next
From:
John Edwards
Date:
February 27, 2002 08:29
Subject:
RE: iteration default variable
Message ID:
2FB59B145095D511A7C90050BAC349F31732D7@MAIL
I don't think there is one. You can maintain a counter for this purpose
though.

my $counter;
for (@answer) {
	#do something ...
	print "On element index $counter\n";
	$counter++;
}

John (Ex OUP...)

-----Original Message-----
From: KAVANAGH, Michael [mailto:Kavanagm@oup.co.uk]
Sent: 27 February 2002 16:26
To: 'beginners@perl.org'
Subject: iteration default variable


Hi there,

This is probably a simple one...

in a loop like this:

for (@answer) {
	#do something ...
}


I understand that for each iteration of the loop, $_ contains the value of
$answer[current iteration].
But is there a default variable I can use to get the current index value?

Can't seem to find the answer anywhere... any ideas would be helpful.

Thanks everybody for contributing to this list... I find it useful.

Thanks
Mike Kavanagh




-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About