Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: To test empty array in perl

by Fletch (Bishop)
on Apr 26, 2010 at 16:03 UTC ( [id://836945]=note: print w/replies, xml ) Need Help??


in reply to Re^2: To test empty array in perl
in thread To test empty array in perl

Using defined on an aggregate's been out of fashion for a good while now.

$ perl -e 'use strict;use warnings;my @foo;if( defined @foo ) { print +"foo" }' |& splain defined(@array) is deprecated at -e line 1 (#1) (D deprecated) defined() is not usually useful on arrays because i +t checks for an undefined scalar value. If you want to see if the array is empty, just use if (@array) { # not empty } for example. (Maybe you should just omit the defined()?)

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^4: To test empty array in perl
by JavaFan (Canon) on Apr 26, 2010 at 16:23 UTC
    And even before it went out of fashion, it never was the correct test whether it contained elements anyway. An array could be defined, yet empty - although it being undefined implied it being empty.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://836945]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-24 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found