The following is a quick and dirty reworking of your code to make it parse under strict and it also uses CGI.pm. It's not guaranteed to work, but if you can cobble it together, it's going to be much easier to maintain. In addition to the 'use CGI or die' post that was mentioned, you might want to read 'use strict' is not Perl to gain insight as to why I eliminated (most) of your global variables.

#!/usr/local/bin/perl -w # Define Variables # use strict; use CGI qw/:standard/; my $basedir = '/home/mysite/www/'; my $baseurl = 'http://www.mysite.com/'; my @files = ('*.htm','*.html','*/*.html'); my $title = "The Silver Machine"; my $title_url = 'http://mysite.com/'; my $search_url = 'http://www.mysite.com/search.html'; # Done # ###################################################################### +######## # Parse Form Search Information # if it's a single form value, map the value as a scalar, other wise, +the value is # and arrayref my %FORM = map { $_, @{[ param($_) ]} > 1 ? [ param($_) ] : param($_) +} param(); # Get Files To Search Through my $files = &get_files; # Search the files my ( $include, $titles ) = search( $files ); # Print Results of Search return_html( $include, $titles ); sub get_files { my @FILES; chdir($basedir); foreach my $file (@files) { my $ls = `ls $file`; my @ls = split(/\s+/,$ls); foreach my $temp_file (@ls) { if (-d $file) { my $filename = "$file$temp_file"; if (-T $filename) { push(@FILES,$filename); } } elsif (-T $temp_file) { push(@FILES,$temp_file); } } } return \@FILES; } sub search { my @FILES = @{$_[0]}; my ( %include, %titles ); my @terms = split(/\s+/, $FORM{'terms'}); foreach my $FILE (@FILES) { my $string; open(FILE,"$FILE") or die "Can't open $FILE for reading: $!"; { local $/; $string = <FILE>; } close(FILE); $string =~ s/\n//g; if ($FORM{'boolean'} eq 'AND') { foreach my $term (@terms) { if ($FORM{'case'} eq 'Insensitive') { if (!($string =~ /$term/i)) { $include{$FILE} = 'no'; last; } else { $include{$FILE} = 'yes'; } } elsif ($FORM{'case'} eq 'Sensitive') { if (!($string =~ /$term/)) { $include{$FILE} = 'no'; last; } else { $include{$FILE} = 'yes'; } } } } elsif ($FORM{'boolean'} eq 'OR') { foreach my $term (@terms) { if ($FORM{'case'} eq 'Insensitive') { if ($string =~ /$term/i) { $include{$FILE} = 'yes'; last; } else { $include{$FILE} = 'no'; } } elsif ($FORM{'case'} eq 'Sensitive') { if ($string =~ /$term/) { $include{$FILE} = 'yes'; last; } else { $include{$FILE} = 'no'; } } } } if ($string =~ /<title>(.*?)<\/title>/i) { $titles{$FILE} = "$1"; } else { $titles{$FILE} = "$FILE"; } } return ( \%include, \%titles ); } sub return_html { my %include = %{$_[0]}; my %titles = %{$_[1]}; open(FH,"../top.html") || die "couldn't open file $!\n"; my @html=<FH>; close(FH); print @html; print "\n <center>\n <h1>Search Results</h1>\n </center>\n"; print "Here ya go, they're in no particular order:<p><hr size=7 wid +th=75%><p>\n"; print "<ul>\n"; foreach my $key (keys %include) { if ($include{$key} eq 'yes') { print "<li class=bullets><span class=bullets><a href=\"$baseu +rl$key\">$titles{$key}</a></span></li>\n"; } } print "</ul>\n"; print "\n"; print "</ul><br><hr size=7 width=75%><P>\n"; print "<ul>\n<li class=bullets><span class=bullets><a href=\"$searc +h_url\">Back to Search Page</a></span></li>\n"; print "<li class=bullets><span class=bullets><a href=\"$title_url\" +>$title</a></span></li>\n"; print "</ul>\n"; print "<hr size=7 width=75%>\n"; print "</body>\n</html>\n"; }

Cheers,
Ovid

Vote for paco!

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re(3): uninitialized values for arrays suddenly appear by Ovid
in thread uninitialized values for arrays suddenly appear by jerrygarciuh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.