Hi Martin,
Not sure how well I'm able to explain this (hopefully one of the gurus here will do a better job) - basically Perl evaluates operations in either a scalar or list context.
In the case of the array test you give, Perl is evaluating the array in a scalar context, which returns the number of elements in the array. If an array is evaluated in list context it returns the elements of the array itself. The behaviour of various functions & operations in each context is dependant on the operation, but is usually fairly intuitive. You can force scalar context using the "scalar" function, so the test could have been written as:
if (scalar(@mydata))
{
print "The array has elements ", scalar(@mydata), "\n"
}
List contect can usually be forced using parentheses (), ie.
my $entireFile = (<FILEHANDLE>); ## this will evaluate the filehandle in list context. Filehandles return the rest of the file when called in a list context.
I had trouble getting my head round this stuff initally, but once you get used to using the different contexts, you realise just how good Perl is at doing what you expect.
If you're not using the Camel Book (Programming Perl) or the Llama Book (Learning Perl), I'd suggest you get them...the Llama book is intended for complete beginners, the Camel book for competent coders moving to Perl, I think.
Anyway, I've probably confused you even more, so I'll leave it at that!
Cheers
Steve