Solved

PERL Script

Posted on 2003-10-31
4
190 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl script to parse xml file 2 104
Port 80 requests 16 87
Migrate OTRS to newest version. 1 312
Control Number of Log Files -Perl 7 55
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now