[Israel.pm] Can anyone explain my mistake ?
Offer Kaye
offer.kaye at gmail.com
Wed Jun 10 05:49:00 PDT 2009
2009/6/10 Berler Chanan :
>
> In the real world (in my way of thinking)
> Foreach should have interpreted into a 'for' loop
>
> Means:
> foreach $elm (@elm_arr) ==> should have been: for ($index = 0; $index >=
> $#elm_arr; $index++) { $elm = $elm_arr[$index]; ..... }
>
> this way my script would have worked.
> Chanan
>
Or to be more precise:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
use strict;
use warnings;
my @arr = (1,2,3,4,5);
my $lv_num;
for ($lv_num = 0; $lv_num <= $#arr; $lv_num++)
{
print "Found $arr[$lv_num]\n";
last if ($arr[$lv_num] == 3);
}
print "arr[lv_num] = $arr[$lv_num]\n";
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Which works but in my eyes is not so pretty as using a foreach loop...
Regards,
--
Offer Kaye
More information about the Perl
mailing list