Dear Wise and Kind Monks:

The code below is mis-behaving when it does not find the XML element it is looking for.
If I look for "IssuerCountry" the correct customBucketValue is returned.

However, if I look for "SandPRating" which is not contained in the customBucketList, the code mis-behaves. In this case @rtnVal returned is defined. I would expect it to be undefined. The code does not do the assignment to @rtnVal so I would expect @rtnVal to be undefined.

many thanks for your kind assistance

kd

sub getCBLValue { my ($cblIn, $cbNameIn); my @cdn = undef; my $textEl = undef; my @rtnVal = undef; # return the CustomBucketValue element #** ** ** ** ** ** ** ** ** # pass in the customBucketList and the name of the # dimension to look for ($cblIn, $cbNameIn) = @_; foreach my $cb ( $cblIn->getChildNodes() ) { if ($cb->getNodeType() == ELEMENT_NODE && $cb->getNodeName() eq 'customBucket' ) { print '$cb node name: ' .$cb->getNodeName() . ' type: ' . n +odeTypeText($cb->getNodeType() ) . "\n"; #scanner( $cb ); @cdn = $cb->getElementsByTagName("customDimensionName", 0); #print scalar @cdn; $textEl = $cdn[0]->getFirstChild(); if ( $textEl->getData() eq $cbNameIn ) { print "\n Assignment to rtnVal "; @rtnVal = $cb->getElementsByTagName("customBucketValue", 0); last; } } # if customBucket node } # foreach print "\n Return from getCBLValue: " ; print ( defined(@rtnVal) ? " defined \n" : " undefined \n" ); return @rtnVal; } # getCBLValue


given a node that contains XML like the following:
<customBucketList> <customBucket> <customDimensionName>GSEC_SecuritySubType</customDimensionName> <customBucketValue>1041</customBucketValue> </customBucket> <customBucket> <customDimensionName>IssuerCountryOfDomicile</customDimensionName> <customBucketValue>US</customBucketValue> </customBucket> <customBucket> <customDimensionName>icbSubSector</customDimensionName> <customBucketValue>Banks</customBucketValue> </customBucket> <customBucket> </customBucketList>



In reply to defined or undef by kevind0718

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.