In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Danny Fang) writes: >--0-972884666-1109846115=:30240 >Content-Type: text/plain; charset=us-ascii > >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?
Did you really post the right code? Because that code has basic syntax errors on line 21 where the programmer has thought that // introduces a Perl comment, and also left out quote marks, thereby doing a division by a string. It should have (probably) generated the error Bareword found where operator expected The code does not use strict, which makes me disinclined to read much more; if someone doesn't ask Perl to help them get their program correct then they should expect obscure problems. I have no idea what line 6 was supposed to be, but it's wrong. The open statement is not checked for success and contains a useless stringification. The first clause of the for statement looks to me like the source of the error you cite (it's a warning). The programmer either didn't understand what a for statement was or was very careless. Either way, there are so many serious errors here that there are sufficient grounds for rejecting the integrity of this program and it should either be rewritten from requirements or every line inspected with a magnifying glass. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>