I apologize if this is a repeat.
The following code works on Perl v5.8.8, but does not on v5.10.0.
#!/usr/bin/perl
use strict;
sub getListIdx {
my $listref = shift;
my $sval = shift;
for (my $i=0; $i<=$#{@{$listref}}; $i++) {
if ($sval eq $listref->[$i]) {
return $i;
}
}
return -1;
}
my @tarray = (3, 5, 6);
for my $i (1,2,3,2,4,5) {
print "i=$i\n";
if (getListIdx(\@tarray, $i) == -1) {
print "Adding unique $i\n";
push @tarray, $i;
} else {
print "Found $i again.\n";
}
}
When run on v5.10.0, I get the following:
Can't use string ("3") as an ARRAY ref while "strict refs" in use at ./x2 line 8.
I presume this has something to do with using the $# syntax to get the length of the array? Is there a better/new way of doing this that works in both versions of Perl?
The following code works on Perl v5.8.8, but does not on v5.10.0.
#!/usr/bin/perl
use strict;
sub getListIdx {
my $listref = shift;
my $sval = shift;
for (my $i=0; $i<=$#{@{$listref}}; $i++) {
if ($sval eq $listref->[$i]) {
return $i;
}
}
return -1;
}
my @tarray = (3, 5, 6);
for my $i (1,2,3,2,4,5) {
print "i=$i\n";
if (getListIdx(\@tarray, $i) == -1) {
print "Adding unique $i\n";
push @tarray, $i;
} else {
print "Found $i again.\n";
}
}
When run on v5.10.0, I get the following:
Can't use string ("3") as an ARRAY ref while "strict refs" in use at ./x2 line 8.
I presume this has something to do with using the $# syntax to get the length of the array? Is there a better/new way of doing this that works in both versions of Perl?