?
Solved

PERL Script

Posted on 2003-10-31
4
Medium Priority
?
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

752 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