in reply to Exists and arrays
Exists checks whether a variable is existing in the array, that is, it has a value associated with it as a result of assignment (i.e. $dow[0]=undef), this is clearly indicated in Perl documentation for Functions, check out both defined and exists functions to decloud the confusion
#!/usr/local/bin/perl use strict; my @dow=(); #array initialization is different from indexes initiali +zation $dow[0]=undef; $dow[6]= "sat"; for(my $i=0; $i <=6;$i++){ if(!(defined($dow[$i]) || exists($dow[$i]))){print "\$dow[$i] +\t not defined\n";} if(exists($dow[$i]) && !defined($dow[$i])){ print "\$dow[$i]\t +exists\t not defined\n"; } if(exists($dow[$i]) && defined($dow[$i])){ print "\$dow[$i]\te +xists\t defined\n" ;} }
|
|---|