in reply to Re^2: $# -variable?
in thread $# -variable?
If someone plays with $[, and you are using a loop as shown above, you have problems with both expressions $#array and scalar(@array).
So, if you want to ensure that your loop does what you want, you have to use this one:
or
So, if you want to ensure that your loop does what you want, you have to use this one:
#!/usr/bin/perl use strict; use warnings; $[ = 3; my @array = qw(1 2 3 4); for my $i($[ .. $[ + (scalar(@array) - 1) ){ print $array[$i],"\n"; }
or
#!/usr/bin/perl use strict; use warnings; $[ = 3; my @array = qw(1 2 3 4); for my $i($[ .. $#array ){ print $array[$i],"\n"; }
In Section
Seekers of Perl Wisdom