The first place in your array is 0, There are a couple of examples of
foreach that I don't mind giving:
my @array = qw{this is the example of the array we will use for this
example};
foreach(@array) {
print $_."\n"; # current element is $_
}
or if you need the index of the array:
foreach (0..$#array) {
print $array[$_]."\n"; # now $_ is current of the count in foreach
}
or you can just go
print $_ foreach (0..100);
or the earlier examples:
print "$_\n" foreach (@array);
Does that help?
Steve H.
-----Original Message-----
From: Evan Panagiotopoulos [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 17, 2001 8:47 PM
To: [EMAIL PROTECTED]
Subject: foreach examples/usage
I am trying to learn the foreach loop. Is there a place on the web where
there are examples for the foreach? Basically I have an array of X elements
and I want to go from the first element (is it zero?) to the last. I have a
variable containing the number of elements in the array. If the array has 22
elements does it go from 0 to 21 or 1 to 22?
Thanks,
Evan Panagiotopoulos
Technology, Library and Media Director
Poughkeepsie City School District
Yes We Can! Watch Us Do It!