Hi, I'm a newbie with Perl and I wrote a perl script (see below) whose function is to read a *.html file and checks to insert the following HTML tags i.e <head>, </head>, </body>, <body>, </script>history.forward( ) if these tags are not present. Content of the html test file are as follows: <html> <form="HITHERE"> HELLO Test file </head> </body> SCRIPT: #!/usr/bin/perl while (<>){ if ($_ !~ /^\<html\>/){ s/^<html\>/<html\>\n<head\>/ } if($_ !~ /<body>/) s/<form\=HI>/<body>\n<form\=HI>/; if($_ !~ /<\/body>/){ s/^<\/form>/<\/form>\n<\/body>/; } if($_ !~ /<\/script>history\.forward\(\)\b/){ if($_ !~ /<\/head>){ s/<\/script>/<\/script>\n<\/head>/; } s/<\/head>/<\/head>\n<\/script>history\.forward\(\)/; } print $_; } However, it produced the error shown below: /opt/WebSphere/admin >>test3.pl testfile.txt syntax error at ./test3.pl line 11, near ") s/<form\=HI>/<body>\n<form\=HI>/" Unmatched ) in regex; marked by <-- HERE in m/</head>) <-- HERE { s/ at ./test3.pl line 17. May I know what is the correct method of matching the contents of the <form> tag? I've arbitrarily placed a string i.e. "HI THERE" for display purposes. May I also know how I could match whatever strings within the <form> tag, along with it's string quotations i.e. "HI"? I tried the following, but it yielded the following results: $perl -pe 's/<form\=(\W+\w+)>/<body>\n<form\=($1)>/ if $_ !~ /<body>/;' testfile.txt <html> <form="HI"> HELLO Test file </head> </body>
I'm expecting that if the tag <body> does not exists, it should then be included into the *.html file immediately below the <form=....> tag i.e. : <html> <body> <form="HI"> HELLO Test file </head> </body> However, it did not. Moreover, may I know how I could rewrite the multiple if statements into an equivalent CASE statement? Could anyone kindly help me out on these matters? Thanks Danny --------------------------------- Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web