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

pls help in perl

by sandhya (Initiate)
on May 11, 2012 at 12:10 UTC ( #969991=perlquestion: print w/ replies, xml ) Need Help??
sandhya has asked for the wisdom of the Perl Monks concerning the following question:

i need coding for the below sentance 1. If the number of details records does not tally with the count given in the Total Count field at the end of the file, then 1.1. Reject the file 1.2. Record the error details in the error log

Comment on pls help in perl
Re: pls help in perl
by uday_sagar (Scribe) on May 11, 2012 at 12:23 UTC
    Sandhya, Can you elaborate your question? I mean, can you pass the file which contains total count field and the error details.
Re: pls help in perl
by BrowserUk (Pope) on May 11, 2012 at 12:23 UTC
    i need coding for ...

    If you need it, try writing it.

    Or read some books and learn how to write it.

    Or employ someone to write it for you.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: pls help in perl
by pemungkah (Priest) on May 11, 2012 at 21:27 UTC
    Enter Perl's English-like syntax:
    # "if..." if ( # the number of details records $details_record_count # does not tally with (is not equal to) != # the count given in the total count fie +ld at the end of the file # (we'll assume you've read the file and + have it already) $total_count) # then { # 1.1 Reject the file push @rejected_files, @filename; # 1.2 Record error details in the error log print $error_log "$file total count field does not agree ($details +_record_count actual, $total_count in file)\n"; }
    Most of the time Perl does a really good job of expressing things in very close to the original English statement. Note that I've left out the reading of the file, extraction of the count, and setup of the error log, because I'm giving you the opportunity to learn how to do that part. Note also that you'll need to print the rejects at the bottom of your program (hint: join("\n",@rejected_files)). I'm providing this to encourage you to go ahead and try stuff and see if it works (writing tests for your program will help with this) because Perl really is very close to a natural language in terms of expressing things. Let's pull those comments out and see how it reads without them:
    # if the number of actual detail records doesn't match the count in th +e file, mark this file as rejected and print a message to the error l +og. if ( $details_record_count != $total_count) { push @rejected_files, @filename; print $error_log "$file total count field does not agree ($details +_record_count actual, $total_count in file)\n"; }
    See? Not hard at all! You can do it. Go ahead and put the comments in to help you think it out if necessary. You can always remove or shorten them when you're done. (Use a revision control system; it'll save you incredible amounts of work.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://969991]
Approved by NetWallah
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (15)
As of 2014-08-22 18:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (163 votes), past polls