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

RE: iteration default variable

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

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

John (Ex OUP...)

-----Original Message-----
From: KAVANAGH, Michael []
Sent: 27 February 2002 16:26
To: ''
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.

Mike Kavanagh

To unsubscribe, e-mail:
For additional commands, e-mail:

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About