P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Several things: This code compiles and has a result. It would be better if you explain why aren't the results to your liking - what is the exact assignment supposed to output. Use the 3 arguments way for open, and if you hard code the file, use a full path. open(FILE, '<', 'c:\results\marks.txt') || die("cannot access the file - $! "); All the variables are being declared at the start, which makes them global to the whole program. This nullify the benefits of scoped calls, and results from one student override the other. Also, the $status is always being set to the last result of the student. You also call %records, without referring to it. A better way would be to declare the variables just before you need them. saying my @details = split (',');instead, is better than your regex matching. You can then check each of @details, remove unwanted characters and process it accordingly. Main reason is that you assume the file is set "john,michael,100,50,60" while it might be "Mr. john-bob,michael-mick ,100 ,50.5 ,60.3,74.29,...."
There's no need for the subroutine checkpass if you only check for the mark being larger than 35. place the check inside the loop and process it if $mark > 35. For instance, if you only want to calculate passed marks, say $total += $mark if $mark > 35; Software speaks in tongues of man. In reply to Re: Students Rank calculation for the below perl script
by Erez
|
|