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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.