Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: defined array question

by htoug (Deacon)
on Aug 30, 2002 at 11:43 UTC ( [id://194073]=note: print w/replies, xml ) Need Help??


in reply to defined array question

I don't get the meaning of this: if( defined @user_geg[0..$#user_geg] ) { }

Now lets see what it means.

  • 0..$#user_geg creates a list of integers from 1 to 27 (in this case). OK.
  • @user_geg[0..$#user_geg] return an arrayslice consisting of elements 1..27 of the array user_geg. By my book this is the same as @user_geg. Hmmm not so good...
  • defined @user_geg (leaving out the 0..27 part for now) is meaningless:
    perldoc -f defined says: Use of "defined" on aggregates (hashes and arrays) is deprecated.. Not OK!

What you probably mean is "if there are any elements in the array 'user_egg' then ..." which can be expressed as
if (@user_geg) { }
See - much simpler.

Your original question as to why you have to add the -1 is probably answered by the meaninglessness of defined @user_geg.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found