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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

i have a database of student name and score of 5 subjects....and the problem is if a student score is less than 50 in any subject then i have to print out the corresponding student name and the subject or subjects in which he score less than 50.here i made the database but having probs in printing out the subject name when he score less than 50 in more than 1 subject..i want the output to be like

Amir fails in : english Maths hindi

if the marks in these 3 subjects is less than 50.

i have written the code like

#!/usr/bin/perl #%studentbase is the hash, my @header = ("Name","English", "History", "Maths","Science","Geography"); $studentcount =0; while ($input =<STDIN>){ $input=~ s/^\s+|\s+\n$//g;#remove the heading n trailing space @subinfo = split (/\s+/,$input); $studentlist[$studentcount++]= $subinfo[0]; for ($count =1; $count <=@subinfo;$count++){ $studentbase{$subinfo[0].$header[$count-1]}=$subinfo[$count-1] +; } } foreach $student(@studentlist){ print " $student fails in :"; for ($count=1;$count <=@subinfo; $count++){ if ($subinfo[$count] <= 50){ print" $header[$count]"; } } }

I am able to get the output for a single line of input but when i give more that 1 line of input I am not able to get the desire output. plz help


In reply to database using associative has by changma_ha

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2022-12-05 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?