Solved

PERL Script

Posted on 2003-10-31
4
193 Views
Last Modified: 2010-03-05
Hi

I am new to this site and i am new to PERL programming also.

I am looking for a help from you.

I am having a requirement which goes like this

I have to write a perl script to read a text file(This text file is having a single column)  -- But before that

1: First I have to check whether that file exist in the path given.If it exist then return 0 otherwise send an email to xyz@xyz.com stating that file not found in the given directory but return 0 right now also.
2: If that file is read permission then return 0 if not then send an email to xyz@xyz.com stating that file is not having read permission but return 0
3: Read the file and if it is having wild characters(*,(,),%,$,@,!,.,{,},[,],",:,;) then send an email to xyz@xyz.com regarding the wild card presence (Along with the line numbers) in the file and return 0.

Means - after running this script - We have to always return a zero but if we find any errors which are mentioned above then we have to send an email.

Can somebody help ???

nbo
0
Comment
Question by:nbotension
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 25 total points
ID: 9661883
You're saying "return 0" when I think you mean "continue on to the next step" at several stages in your description.

There is no point to separately checking for the existence and readability of the file. That leaves us with just two things to check: 1) can we open the file for reading? and 2) does the file contain any forbidden characters?

Let's assume you have already figured out how to send an email and that knowledge is embedded in a subroutine named "send_error_email" which takes as its single argument a string containing the error message that is to be sent.

Let's assume the "given path" is in the variable $path.

Let's assume the file name is in the variable $file.

That means the basic script will look something like this one:

use strict;

my $badchars = q/*()%$@!.{}[]":;/;

open FILE, "$path/$file" or do {
               send_error_email( "could not open $path/$file for reading because $!";
               exit 0;
               };

while( <FILE> ) {
              if ( tr/$badchars// ) {
                  send_error_email( "Bad characters found in $path/$file at line $.");
                  last;
                }
              }
exit 0;
0
 
LVL 48

Expert Comment

by:Tintin
ID: 9662052
Sounds very much like homework, which is not permitted under EE guidelines.

Please clarify what the "requirement" is.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10038315
Nothing has happened on this question in over 2 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by jmcg (or delete, forfeit points because it's homework).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Validating the data using Oracle DBD module. 5 67
Problem with one substitution modifying another 3 73
How to get all the API from website? 11 104
perl getopt long help 34 70
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question