Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Students Rank calculation for the below perl script

by Erez (Priest)
on Apr 15, 2008 at 07:47 UTC ( [id://680446]=note: print w/replies, xml ) Need Help??


in reply to Students Rank calculation for the below perl script

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;
Last, no need for concatenation, Perl can do $string = "$var $var1, $var2 $var3\n".

Software speaks in tongues of man.
Stop saying 'script'. Stop saying 'line-noise'.
We have nothing to lose but our metaphors.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found