Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Probelm with priority printing (hash or by an array)

by eighty-one (Curate)
on Nov 06, 2008 at 14:17 UTC ( #721998=note: print w/replies, xml ) Need Help??


in reply to Probelm with priority printing (hash or by an array)

Hello,

The Perl hast How-To may be of use. A hash of arrays would solve the problem of having a hash of priorities with multiple diseases each having the same priority. But, an array of arrays would as well.

What's in the database? Knowing how that data is presented might be helpful.

EDIT:

I think I might have a better idea of what you're looking for. You could try something like this:

#!/usr/bin/perl -w use strict; my @diseases = (); $diseases[0] = ['flu','cold']; $diseases[1] = ['Diabetics']; $diseases[2] = ['Typhoid']; $diseases[3] = ['Measels']; for(my $priority = 0;$priority < scalar(@diseases);$priority++){ print "Priority $priority diseases:\n"; foreach(@{$diseases[$priority]}){ print "\t$_\n"; } }
which produces output like this:
Priority 0 diseases: flu cold Priority 1 diseases: Diabetics Priority 2 diseases: Typhoid Priority 3 diseases: Measels
but within that inner foreach loop, run a query; something like "SELECT * WHERE disease_name = $_" and format and print the results as needed.

EDIT #2: Just noticed; you need to add 1 to $priority when printing to make it display properly, since your priority list starts with '1' and not '0'.

Replies are listed 'Best First'.
Re^2: Probelm with priority printing (hash or by an array)
by Anonymous Monk on Nov 07, 2008 at 10:29 UTC
    Hi, Thanks for your suggestion. But when printing the results from the database it prints in the same order as it fetches. Also, I have two sets of diseases. Say: disease_1:
    1 flu 1 cold 2 measles

    and another set of disease like:
    1 diabetes 2 typhoid

    Those two sets are distinguished based on the process they go for. there may be some disease which appears in both the sets.
    The diseases are not the exact names but an example of it. The Query fetches different process that the disease has passed through. But I think that doesn't matter us much(!) here. The problem is I am having the same problem again that is ,the order of the disease is not in the order that I have got in the array but IT comes randomly as it fetches in the database. for example:
    XXX:measles 45 35 67 1000 XXX:flu 67 35 45 7000 XXX:typhoid 56 78 89 1000

    Note the XXX:disease is the way the disease is stored inthe database.
    What I need to have is the exact order and priority number along with the exact names that I have stored in the array.
    Thanks for your suggestions.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2021-10-24 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?