Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: foreach not doing what I expect it to be doing

by revdiablo (Prior)
on Feb 08, 2006 at 21:19 UTC ( [id://528939]=note: print w/replies, xml ) Need Help??


in reply to foreach not doing what I expect it to be doing

You are creating an array with only a single element. That single element happens to be an array reference. So the foreach loop is working how you expect, it's your earlier assignment that isn't. You might have better luck by dereferencing the arrayref on assignment (note, this makes a copy. Depending on the circumstances, that may be bad):

my @bucketList = @{ $_xmlData->{Bucket} }; ...

See also perlreftut for a nice references tutorial, or perlref for the full reference docs.

Replies are listed 'Best First'.
Re^2: foreach not doing what I expect it to be doing
by Articuno (Beadle) on Feb 08, 2006 at 21:31 UTC
    Also, but not related to your problem, you should open your bucket.txt only once, otherwise it'll be overwritten on each iteration.
    open(DEBUG, ">bucket.txt"); foreach my $bucket ( @bucketList ) { print DEBUG Dumper($bucket); } close(DEBUG);
    -- 6x9=42
      That, or open it with >> instead of >. But your solution is better overall, I am just stating a TIMTOWTDI.

      Update: Mental note, read all replies before responding!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-23 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found