Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Using undef scalar as arrayref

by shemp (Deacon)
on Aug 12, 2005 at 20:36 UTC ( [id://483398]=note: print w/replies, xml ) Need Help??


in reply to Re: Using undef scalar as arrayref
in thread Using undef scalar as arrayref

Ack, you're right about what you noticed about line 5. I goofed. You're also right about the defined test.

The only caveat i can think of is that if the $arrayref got set to an empty arrayref, i'd still not want to do the if conditional (in this situation). So i think the final will be:

if ( $arrayref && @$arrayref ) {
which will throw an exception if its not an arrayref.

I use the most powerful debugger available: print!

Replies are listed 'Best First'.
Re^3: Using undef scalar as arrayref
by Joost (Canon) on Aug 12, 2005 at 20:44 UTC
      Actually the if is separate from the loop. If there are any elements in the arrayref a flag needs to be set for later that is separate from what is happening in the loop. So its something like this:
      if ( $arrayref && @$arrayref ) { # set the flag } ... foreach my $element (@$arrayref) { # do stuff }
      Of course i could set it in the loop, but then its being set multiple times.

      I use the most powerful debugger available: print!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-16 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found