Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PERL Script

Posted on 2003-10-31
4
Medium Priority
?
200 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
3 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 100 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans
Suggested Courses

810 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