Current location: Hot Scripts Forums » Programming Languages » Perl » help with perl


help with perl

Reply
  #1 (permalink)  
Old 02-24-10, 03:21 PM
dogukan82 dogukan82 is offline
New Member
 
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
help with perl

hi there
i have a problem and i need a help

in this problem
1) When run, the program should check if an argument has been provided. If not, the program should prompt for, and accept input of, a filename from the keyboard.

2) The filename, either passed as an argument or input from the keyboard, should be checked to ensure it is in MS-DOS format. The filename part should be no longer than 8 characters and must begin with a letter or underscore character followed by up to 7 letters, digits or underscore characters. The file extension should be optional, but if given is should be ".TXT" (upper- or lowercase).

If no extension if given, ".TXT" should be added to the end of the filename. So, for example, if "testfile" is input as the filename, this should become "testfile.TXT". If "input.txt" is entered, this should remain unchanged.

3) If the filename provided is not of the correct format, the program should display a suitable error message and end at this point.

4) The program should then check to see if the file exists using the filename provided. If the file does not exist, a suitable error message should be displayed and the program should end at this point.

5) Next, if the file exists but the file is empty, again a suitable error message should be displayed and the program should end.

6) The file should be read and checked to display crude statistics on the number of characters, words, lines, sentences and paragraphs that are within the file.


i have tried to some thing but it doesnt work
please help me
thank you

Code:
if ($#ARGV == -1) 
 
print("Please Enter Filename: "); 
$filename = <STDin>; 
chomp($filename); 

else 
{ 
$filename = $ARGV[0]; 
} 
if ($filename !~ m/^[_a-zA-Z0-9]{1,7}\.TXT$/i) 
{ 
die("File is not valid.\n"); 
} 

if (!-e $filename) 
{ 
die("File does not exist\n"); 
} 

#check if filename is empty, exit if it is. 
if (!-s $filename) 
{ 
die("File is empty\n"); 
}

 

open(READFILE, "<$filename") or die "Can't open file \"$filename\":$!";

Last edited by dogukan82; 02-24-10 at 03:25 PM. Reason: add code
Reply With Quote
  #2 (permalink)  
Old 03-24-10, 05:27 PM
mhlelite_moose mhlelite_moose is offline
New Member
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
This sounds like a school assignment lol! Good luck bud!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Modules Polcham Perl 0 09-23-09 01:16 AM
Perl subsititution on Windows kenkanya Perl 3 07-28-09 12:23 AM
Perl upload progress bar with these spec: scott2500uk Script Requests 4 03-16-07 04:04 PM
Perl for a dummy kragnesb414 Perl 1 01-31-06 04:34 AM
Perl FormMail Problem ennanguyen2002 Perl 2 03-09-05 04:47 PM


All times are GMT -5. The time now is 04:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.