$h4X4_|=73}{ has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array skips number if checked for defined.
by Athanasius (Archbishop) on Jun 26, 2016 at 14:35 UTC | |
|
Re: Array skips number if checked for defined.
by hippo (Archbishop) on Jun 26, 2016 at 14:06 UTC | |
|
Re: Array skips number if checked for defined.
by FreeBeerReekingMonk (Deacon) on Jun 26, 2016 at 14:59 UTC |