Results 1 to 4 of 4
10-20-2006, 01:14 AM #1
I have an assignment to do where one question is to create a Perl program, I'm not asking for anyone to do it for me, but to point me in the right direction, and I will be most grateful, I have to;
"Create a Perl script which converts HTM tags into uppercase for a given file. When run, the script should prompt the user to enter name of the HTML file. This name should be varified to ensure the file extension is either .html or .htm (uppercase or lowercase is acceptable) and if not, an error message should be displayed and the user prompted to re-enter the name.
On input of a validated name, the file should be processed (if it exists) and all lowercase tags, converted into uppercase. You should not convert any other text, and should and should also avoid converting tag attribute values.
At the end of the processing, the original file should be renamed with the old extension, instead of .html or .htm, and the processed file be given the original file name.
I have a few vague ideas about what I may do with some bits, but it seems a bit bizarre, can anybody help?
Last edited by HTML; 10-20-2006 at 06:11 AM.
10-21-2006, 10:41 PM #2
well... i am very rusty on my perl and have not really used it in applicaion purpises (i use it in web purpises)...
anyway... i am not sure if you have ever delt with Regular Expressions, but when doing some of the matches like you want they are beautifol...
for example... (.*) means any character 0 or more times... in other words anything
so to match the type of file you can do something like:
that will search for "(anything).html" or .htm
to check a file... well i havent used perl for a while, but i did drag some of my old work out and you should beable to just open the file to test it for example:
open(ADD, "<$folderlocation/settings.txt")|| print "your file is un-readable or does not exist";
to rename a file:
rename("file.txt", "file-old.txt") || die "Cannot rename file.txt: $!";
to check for html tas is also a regual expression thing... example:
$string =~ s/<[0-9a-zA-Z_-]*( |>)(.*)/<[0-9A-ZA-Z_-]$1$2/g
^ is untested so not sure if it will work or not, but something like that.
other than that you SHOULD beable to do the rest.
10-22-2006, 07:25 AM #3
Thank you, I had a feeling about using regular expressions, the part i was most stuck on was the renaming of the file
10-22-2006, 05:25 PM #4