Beefy Boxes and Bandwidth Generously Provided by pair Networks
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;
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.


In reply to Re: Students Rank calculation for the below perl script by Erez
in thread Students Rank calculation for the below perl script by valavanp

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?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found