Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: pls help in perl

by pemungkah (Priest)
on May 11, 2012 at 21:27 UTC ( [id://970105]=note: print w/replies, xml ) Need Help??


in reply to pls help in perl

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://970105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-03-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found