On Wed, Feb 13, 2002 at 01:14:50PM -0800, John wrote:
> Recently someone pointed out that it's better to use:
>
> while( defined( my $line = <HANDLE> ))
>
> than
>
> while( my $line = <HANDLE> )
In more recent versions of Perl (5.00503 and above) there is no need to wrap
a defined around this specific looping process (with a variable and a file
read). Just like while (<HANDLE>) while (my $line = <HANDLE>) has been
special-cased to be equivalent to while (defined(my $line = <HANDLE>)).
AFAIK this only applies to file reads, nothing else. You don't get an
implicit defined around something like while (my $foo = bar()).
That's not to say you shouldn't use the explicit defined, especially if your
script might be run with an older Perl.
> while( defined( my @data = $sth->fetchrow_array()))
See perldoc -f defined, it will describe what defined(@array) means, and
basically how it's useless.
> this does not work - @data is defined (as a zero item array?) even
> when no record is returned. Is the correct coding:
>
> while( defined( my @data = $sth->fetchrow_array()) && $#data > -1 )
I'd suggest:
while (my @data = $sth->fetchrow_array) { ... }
or
while (defined(my $data = $sth->fetchrow_arrayref)) { ... }
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]