in reply to Why is this not finding my array value.

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"; }

Replies are listed 'Best First'.
Re: Re: Why is this not finding my array value.
by basicdez (Pilgrim) on Jan 19, 2001 at 21:36 UTC
    The only reason I was using my $arg = shift(@ARGV) was because this was a quick little script to get the passing of a variable to work. I am going to now implement it into a program that uses XML::Simple and parses an XML tree and evaluates a main Bank number coming in to manipulate between one test environment and the other. this saves a ton of time for my configuration team and others. I will not be using the passing a variable in production. Your other help worked perfectly and I am now in line towards a better understanding of all of this array referencing stuff. Thanks so much for you help. Greatly appreciated. As Thorin would say "I am forever in service to you!" :)