Ron Woodall wrote: > > Hi All: Hello,
> This is a convoluted problem and I hope I can describe it properly. > > I have about 90 html pages. I am extracting a small amount of > information from each page and using that to create 90 more pages elsewhere > in the site. > > What is happening is that I'm getting the information, assembling > it correctly and putting it out to the new file. However, randomly, I'm > getting information repeated in the new file that I cleared. Which file? > The result is > a new file that is 900+KB instead of the intended 10KB. > > An almost identical structure in another sub-routine works > perfectly. Thanks for the help. Here's the code that I'm using: Are you running this code on Perl4? If you are using Perl5 then you should be using lexical variables. (BTW I had to run this through Perltidy so I could actually read it :-) > #================ start update CSS sub-menus > ========================== > sub assemblecsssubmenus { > opendir(PROPFILES,"$basedir/properties\-list"); ^^^^^^^^ ^^ You should _always_ verify that the directory opened. You should pass $basedir and declare it locally instead of using a global variable. A hyphen doesn't need to be escaped in a double quoted string or regular expression. opendir PROPFILES, "$basedir/properties-list" or die "Cannot open $basedir/properties-list: $!"; > @dirlist = readdir(PROPFILES); closedir(PROPFILES); > splice (@dirlist,0,2); This will remove valid files on file systems that do not have the '.' and '..' directory entries. > foreach $inproplist (sort @dirlist) { Does the file list have to be sorted? > if (-d $inproplist) {} > elsif ($inproplist =~ /\.htm/) { You could do all this filtering and sorting when you read the directory. my @dirlist = sort grep { !-d and /\.htm$/ } readdir PROPFILES; > print "$inproplist \n"; > open (INPROPLISTS, > "<$basedir/properties\-list/$inproplist"); You should _always_ verify that the file opened. open INPROPLISTS, "<$basedir/properties\-list/$inproplist" or die "Cannot open $basedir/properties-list/$inproplist: $!"; > @indetail = <INPROPLISTS>; close > (INPROPLISTS); > for ($w=0; $w<=$#indetail; $w++) { The more Perlish way to do this is: for my $w ( 0 .. $#indetail ) { > if ($indetail[$w] =~ m|^<!-- start > property (.*?): -->|i) {$propname = $1; > $indetail[$w+1] =~ /id="(.*?)"/; > $target = $1; You shouldn't use the numerical scalars unless the regular expression matched. $target = $1 if $indetail[$w+1] =~ /id="(.*?)"/; > $outmenuprop1 = "<span > class=\"alpha1\"><img src=\"indent.gif\" height=\"0\" width=\"10\"><a > href=\"../../properties-list/$propname.htm#$target\" > target=\"right\">$propname:</a><br></span>\n"; > push @outmenuprop, $outmenuprop1; > undef $outmenuprop1; Why just push the string instead putting it in a variable and pushing the variable? If you _are_ using Perl5 then use the qq// operator and avoid all the backslashes. push @outmenuprop, qq(<span class="alpha1"><img src="indent.gif" height="0" width="10"><a href="../../properties-list/$propname.htm#$target" target="right">$propname:</a><br></span>\n); > print "."; > } > elsif ($indetail[$w] =~ m|^<!-- start > value $propname: (.*?) -->|i) {$valname = $1; > $indetail[$w+1] =~ /id="(.*?)"/; > $target = $1; $target = $1 if $indetail[$w+1] =~ /id="(.*?)"/; > $outmenuprop1 = "\t<span > class=\"alpha2\"><img src=\"indent.gif\" height=\"0\" width=\"26\"><a > href=\"../../properties-list/$propname.htm#$target\" > target=\"right\">$valname </a><br></span>\n"; > push @outmenuprop, $outmenuprop1; > undef $outmenuprop1; print "."; push @outmenuprop, qq(\t<span class="alpha2"><img src="indent.gif" height="0" width="26"><a href="../../properties-list/$propname.htm#$target" target="right">$valname </a><br></span>\n); > } > elsif ($indetail[$w] =~ m|^<!-- start > copyright -->|i) {} Why include this elsif statement? > } > > @outmenu = split /\z/, <<"endpmenu"; If you are using Perl4 this is the same as split /z/. If you are using Perl5 the \z is special in regular expressions. perldoc perlre [snip] \z Match only at end of string > <html>\z > <head>\z > <title>$propname properties and values menu - > htmlcompendium.org</title>\z > <!-- start meta load -->\z > <meta name="description" content="a description of the > $propname properties and values.">\z > <meta name="keywords" content="Cascading Style Sheets, > CSS, documentation, reference, manual, examples, properties, values, tips, > tricks, HTML">\z > <meta name="rating" content="general">\z > <meta name="author" content="Ronald F. Woodall">\z > <meta name="copyright" content="Copyright 1995, 1996, > 1997, 1998, 1999, 2000, 2001, 2002 by Ronald F. Woodall, Oxford-on-Rideau, > Canada">\z > <meta http-equiv="reply-to" > content="nor\@htmlcompendium.org%20(compendium%20comments)">\z > <!-- end meta load -->\z > <!-- start style load -->\z > <link rel="stylesheet" type="text/css" > href="menucomp900.css" title="0comp700">\z > <!-- end style load -->\z > </head>\z > <body bgcolor="#ffffff" text="#000000" link="#8a8a8a" leftmargin="0" > topmargin="0" marginheight="0" marginwidth="0" title="Resize this window > and/or use the scroll bar to view the entire properties/values list!">\z > endpmenu > > push @outmenu, @outmenuprop; > undef @outmenuprop; If you want to clear out an array then assign a null list: @outmenuprop = (); > $outmenu1 = "<\/body>\n<\/html>\n"; > push @outmenu, $outmenu1; push @outmenu, @outmenuprop, "</body>\n</html>\n"; > undef $outmenu1; If you want to clear out a scalar then assign a null string or the value undef: $outmenu1 = ''; # OR $outmenu1 = undef; > open (OUTPROPMENU, > ">$basedir/Menus/properties/$inproplist"); You should _always_ verify that the file opened. open OUTPROPMENU, ">$basedir/Menus/properties/$inproplist" or die "Cannot open $basedir/Menus/properties/$inproplist: $!"; > print OUTPROPMENU @outmenu; > close (OUTPROPMENU); > print "\n\@outmenu count is: $#outmenu -- "; ^^^^^^^^^ @outmenu in a scalar context will give you the _actual_ count. print "\n\@outmenu count is: " . @outmenu . ' -- '; > undef @outmenu; @outmenu = (); > print "\@outmenu count is: $#outmenu\n"; > undef $propname; > $menucounter++; > undef @indetail; > } > } > $historyline = "$menucounter CSS menus were created\n"; > open (HISTORY, ">>$dirname/$version/000history.txt"); You should _always_ verify that the file opened. open HISTORY, ">>$dirname/$version/000history.txt" or die "Cannot open $dirname/$version/000history.txt: $!"; > print HISTORY $historyline; close (HISTORY); > undef $historyline; undef $menucounter; > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]