Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: sorting an array from two sources

by pzbagel (Chaplain)
on Oct 21, 2003 at 22:18 UTC ( [id://301092]=note: print w/replies, xml ) Need Help??


in reply to sorting an array from two sources

We're going to need more information. What are you doing with $sortfield. All the code does is keep changing it based on the existance of $IDNumber in %sort_file. Did you snip too much out of your loop? Did you mean to make $sortfield a hash or array of some sort. Your logic is sound up until that last if statement which just keeps changing the value of $sortfield over and over.

Later

P.S. Even if you are missing too much out of your loop, I think I spotted the logic error in your if statement. You assign $total_points when what you really want to assign is $sort_file{$IDNumber} since it is storing the value of $total_points for that hash key. Change it to:

if (exists ($sort_file{$IDNumber} )) { $sortfield = $sort_file{$IDNumber}; } else { $sortfield = ""; }

Replies are listed 'Best First'.
Re: Re: sorting an array from two sources
by Anonymous Monk on Oct 21, 2003 at 22:56 UTC
    Thanks very much for your input, pzbagel.

    I'm afraid I was careless in putting together my sample code. $sortfield is the first field of the db as follows:

    ($sortfield,$undef,$IDNumber,$Email_address,$Page_Name)=split (/\t/,$l +ine);
    What I want to achieve is each time the main db is iterated, the second db is serched for the IDNumber. If it exists the $total_points will be stored in the $sortfield for that line, otherwise it is undefined. I can then sort the main db according to the values of $sortfield.

    I tried your update above, and thought it made sense. However it didn't work so I think my logic must be awry somewhere along the line.

    Thanks once again

Log In?
Username:
Password:

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

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

    No recent polls found