Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

using the define option

by Anonymous Monk
on Aug 22, 2001 at 13:10 UTC ( #106897=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am using this code : if (defined @array ) { print "Array is found"; } but it doesn't work, something is wrong and it doesn't print my message. what is wrong with it, thanks.

Colin.



Edit Masem 2001-08-22 - Removed offensive sig line

Comment on using the define option
Re: using the define option
by azatoth (Curate) on Aug 22, 2001 at 13:13 UTC

    perldoc -f defined.

    Quoth the Perldoc : "...You may also use defined() to check whether a subroutine exists. On the other hand, use of defined() upon aggregates (hashes and arrays) is not guaranteed to produce intuitive results, and should probably be avoided."

    "This counterintuitive behaviour of defined() on aggregates may be changed, fixed, or broken in a future release of Perl." Unquoth the Perldoc.

    This is why you're having problems. Also, remove that .sig. It's offensive.

    Azatoth a.k.a Captain Whiplash

    Make Your Die Messages Full of Wisdom!
    Get YOUR PerlMonks Stagename here!
    Want to speak like a Londoner?
Re: using the define option
by Cine (Friar) on Aug 22, 2001 at 13:28 UTC
    defined @array is deprecated, just use if (@array) instead

    T I M T O W T D I
Re: using the define option
by dmmiller2k (Chaplain) on Aug 22, 2001 at 16:29 UTC

    Arrays cannot be tested for defined(), only scalars can.

    Arrays can be tested for emptiness, as:

    # the scalar of an array is its number of elements if ( scalar(@array) ) { ... } # or equivalently, and shorter # exactly the same thing, since 'if ()' forces scalar context if ( @array ) { ... }

    dmm

    Just call me the Anti-Gates ...
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://106897]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-10-02 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (64 votes), past polls