I have some thing happening in a package that seems strange to me. Lets say I have a blank array @array = (); when I check if the array{hash} is defined that should not be. Then push to that array and check the number again the array shifts to the next number.
I hope the code explains it better...

#!/usr/bin/perl use warnings; use strict; # add to @Foo::THING push(@Foo::THING, { 'check' => '1',} ); # Should say "Some Thing" Foo::check_THING(0) ? print "Some Thing\n" : print "No Thing\n"; # Should say "No Thing" Foo::check_THING(1) ? print "Some Thing\n" : print "No Thing\n"; # add to @Foo::THING push(@Foo::THING, { 'check' => '1',} ); # Check if it was added? Foo::check_THING(1) ? print "Some Thing\n" # I think it should be this : print "No Thing\n"; # But we get this # Why is it 2? Foo::check_THING(2) ? print "Some Thing\n" # WTF? : print "No Thing\n"; package Foo; our @THING = (); sub check_THING { my $id = shift; defined $THING[$id]{check} ? return 1 : return 0; }


In reply to Array skips number if checked for defined. by $h4X4_|=73}{

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.