in reply to exists and defined functions
As of Perl 5.6.0, the exists function can be used on arrays to test the existence of an element within an array. For example:
my %hash = ( 'key' => 'value' ); print "exists \$hash{'key'}\n" if exists $hash{'key'}; my @array = ( 'value' ); print "exists \$array[\$index]\n" if exists $array[0];
Under Perl 5.005.03 this code results in an error:
exists operator argument is not a HASH element at test-5.00503.perl li +ne 7.
Whereas, under Perl 5.6.0 or later, the code executes without error:
exists $hash{'key'} exists $array[$index]
As such, your solution here will be to employ a newer version of Perl, rewrite your code to use the defined function as suggested by the other posts in this thread, or check your index against the value of $#exp (the index of the highest array element).
perl -e 'print+unpack("N",pack("B32","00000000000000000000000111101000")),"\n"'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: exists and defined functions
by tye (Sage) on Nov 20, 2002 at 22:09 UTC |