in reply to Arrays to Hash Issue

Having synchronized lists is usually an easy way to introduce bugs, but is sometimes the best answer. Do the order of the accounts matter? Can you have repeat names or repeat account numbers? If the answer to both is no, a simple way to implement what I assume you mean to accomplish (your $c = -1 means you output the same name over and over) using a hash would be:

#sample code ... my %name; foreach my $acc ($xml->findnodes('/account')) { $name{$acc->find('numbers')} = $acc->find('names'); } foreach (keys %name) { print "Account: <b>$_</b> - Name: $name{$_}"; } ...

Replies are listed 'Best First'.
Re^2: Arrays to Hash Issue
by BrowserUk (Patriarch) on Sep 10, 2010 at 18:28 UTC

    One change I'd make to that, is to use while each instead of for if there is any chance that this list can grow to any substantial size.

    while( my( $account, $name ) = each %names ) { print "Account: $account Name: $name\n" }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.