I'm a level 10 C/C++ coder, level 2 ASM coder, and now need to tri-class with Perl. Here is a bit of code I'm having trouble with:
my @bucketList = $_xmlData->{Bucket}; open(DEBUG, ">bucketList.txt"); print DEBUG Dumper(@bucketList); close(DEBUG); foreach my $bucket ( @bucketList ) { open(DEBUG, ">bucket.txt"); print DEBUG Dumper($bucket); close(DEBUG); }
$_xmlData holds the data returned from an XML::Simple::XMLin call, Bucket being the key that references an array of all these things called buckets. Dumper is a function in Data (not sure if it's a commonly used tool, but it seems to print out arrays and hashes nicely). Trying to handle this with a foreach loop, I put all that data into @bucketList. The dump shows that it is all ok. The problem is with my foreach variable, $bucket. I would think that it would be set to each element of @bucketList sequentially. According to the dump, it's actually set to the entire array. What am I doing wrong? as requested, here are snippets of the dumps: bucketList:

$VAR1 = [ { 'ExeVersion' => NDA_BLOCKED, 'ModuleVersion' => NDA_BLOCKED, 'ResponseStatus' => NDA_BLOCKED, 'ExeName' => NDA_BLOCKED, 'Priority' => NDA_BLOCKED, 'TotalHits' => NDA_BLOCKED, 'ResponseURL' => NDA_BLOCKED, 'ModuleName' => NDA_BLOCKED, 'BucketID' => NDA_BLOCKED' }, { 'ExeVersion' => NDA_BLOCKED, 'ModuleVersion' => NDA_BLOCKED, 'ResponseStatus' => NDA_BLOCKED, 'ExeName' => NDA_BLOCKED, 'Priority' => NDA_BLOCKED, 'TotalHits' => NDA_BLOCKED, 'ResponseURL' => NDA_BLOCKED, 'ModuleName' => NDA_BLOCKED, 'BucketID' => NDA_BLOCKED' }, { 'ExeVersion' => NDA_BLOCKED, 'ModuleVersion' => NDA_BLOCKED, 'ResponseStatus' => NDA_BLOCKED, 'ExeName' => NDA_BLOCKED, 'Priority' => NDA_BLOCKED, 'TotalHits' => NDA_BLOCKED, 'ResponseURL' => NDA_BLOCKED, 'ModuleName' => NDA_BLOCKED, 'BucketID' => NDA_BLOCKED' }]

bucket:

$VAR1 = [ { 'ExeVersion' => NDA_BLOCKED, 'ModuleVersion' => NDA_BLOCKED, 'ResponseStatus' => NDA_BLOCKED, 'ExeName' => NDA_BLOCKED, 'Priority' => NDA_BLOCKED, 'TotalHits' => NDA_BLOCKED, 'ResponseURL' => NDA_BLOCKED, 'ModuleName' => NDA_BLOCKED, 'BucketID' => NDA_BLOCKED' }, { 'ExeVersion' => NDA_BLOCKED, 'ModuleVersion' => NDA_BLOCKED, 'ResponseStatus' => NDA_BLOCKED, 'ExeName' => NDA_BLOCKED, 'Priority' => NDA_BLOCKED, 'TotalHits' => NDA_BLOCKED, 'ResponseURL' => NDA_BLOCKED, 'ModuleName' => NDA_BLOCKED, 'BucketID' => NDA_BLOCKED' }, { 'ExeVersion' => NDA_BLOCKED, 'ModuleVersion' => NDA_BLOCKED, 'ResponseStatus' => NDA_BLOCKED, 'ExeName' => NDA_BLOCKED, 'Priority' => NDA_BLOCKED, 'TotalHits' => NDA_BLOCKED, 'ResponseURL' => NDA_BLOCKED, 'ModuleName' => NDA_BLOCKED, 'BucketID' => NDA_BLOCKED' }]

Code tags added by Arunbear


In reply to foreach not doing what I expect it to be doing by skorman00

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.