Hi, 
 
I've a script below which reads the contents of a text file which contains the 
output of the `ls -lR` in UNIX. This script reads the list of html files 
contained in the text file, and for every file it checks to see it contains 
some specified HTML tags or not. If it does not, this script then inserts the 
specified tag (hardcoded in this script) into the respective HTML file.     
 
## test3b.pl
#!/usr/bin/perl/perl -w
$infile = shift(@ARGV);
open(INFILE, "$infile");    ## reads input file from command line - results of 
'ls -lR'
while(<INFILE>){
   next if(/total\d+/);    ## ignore total XXX in the output of ls -lR
   next if(/$/);
   if(/:$/){
      chomp;
      s/://;
      $path = $_;   ## get path name of the file in ls -lR
   }
   else{
      @array = split(/\s+/, $_);
      $fileName = $array[8];
      $timeVal = $array[7];
      open(HTMLFILE, "$fileName");
      @htmlContents = <HTMLFILE>;
      for($i; $i<@htmlContents; $i++){
         if($htmlContents[$i] !~ /<head>/){
            open(NOHEAD, ">NoHead.txt");  
            print NOHEAD $path/$fileName;   //compile a list of html files 
which do not have <head>
            close(NOHEAD);
         }
         if($htmlContents[$i] !~ /^<\/script>history\.forward\(\)\b/){
            if($htmlContents[$i] =~ /<head>/){
               s/<\/head>/<\/script>history\.forward\(\)\n<\/head>/;
               open(REPLACEMENT, ">$path/$fileName");
               print REPLACEMENT "$htmlContents[$i]";  ## rewrite substituted 
value back to original file.
               close(REPLACEMENT);
            }
        }
      }
      close(HTMLFILE);
   }
}
close(INFILE);
 
However, I obtained the error below("Useless use of a variable in void context 
at ./test3b.pl line 37") below,  in which I'm do not how I could resolve it:
 
/opt/IBM/WebSphere/admin >>./test3b.pl /tmp/lender.txt
Useless use of a variable in void context at ./test3b.pl line 37.
Name "main::timeVal" used only once: possible typo at ./test3b.pl line 19.
 
Could anyone kindly help me out with this error? 
 
Any suggestions or critique to this script is indeed welcomed. 
 
Thanks
 

                
---------------------------------
Celebrate Yahoo!'s 10th Birthday! 
 Yahoo! Netrospective: 100 Moments of the Web 

Reply via email to