my first suggestion: use strict;.
my second suggestion: use Data::Dumper;
learn them, love them, debug problems like this much easier.
if you used strict, you would see this error:
Global symbol "a1" requires explicit package name at practice/temp lin +e 20. Global symbol "a2" requires explicit package name at practice/temp lin +e 28.
from there, you'll see that you need to dereference.
print "$#a1\n"; becomes print "$#$a1\n";
and if ($a1[$BankCount] eq $arg) becomes
if ($a1->[$BankCount] eq $arg)
that said, i don't really understand what you're doing with my $arg = shift(@ARGV); --when i run your program, i get use of unitialized value where you try to compare against $arg. are you passing your $arg in off the command line?
here's what i get running your script with use strict;, Data::Dumper, and the array reference fixes:
$VAR1 = [ 1, 2, 3 ]; $VAR1 = [ 4, 4, 4 ]; 2 Use of uninitialized value at practice/temp line 25. Use of uninitialized value at practice/temp line 25. Use of uninitialized value at practice/temp line 25. Use of uninitialized value at practice/temp line 34.
here's the code:
use strict; use Data::Dumper; my @BankIN = (1,2,3); my @BankOUT = (4,4,4); use strict 'subs'; arrayX(\@BankIN, \@BankOUT); sub arrayX{ my($a1, $a2)=@_; print Dumper($a1); print Dumper($a2); my $BankCount = 0; my $arg = shift(@ARGV); print "$#$a1\n"; while ($BankCount <= $#$a1 ) { if ($a1->[$BankCount] eq $arg) { $arg = $a2->[$BankCount]; $BankCount = $#$a1; } $BankCount++; } print "$arg\n"; }
In reply to Re: Why is this not finding my array value.
by cat2014
in thread Why is this not finding my array value.
by basicdez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |