in reply to Erroneous defined detection of array elements
You probably meant my $number=shift; (not $my number=shift; — though that would produce a different error message).
Other than that, I don't see anything wrong with testing not defined ($array[$number]) to do what you want, and in fact it does work just fine for me... (in other words, I suppose the problem lies elsewhere).
#!/usr/bin/perl use strict; use warnings; my @array; $array[70] = "foo"; asubroutine(20); sub asubroutine { my $number=shift ; # $number takes the value of 20 if ( not defined ($array[$number])) { print "There is no such element $number in the array.\n"; } } __END__ There is no such element 20 in the array.
|
|---|