Apple seemed to work fine for me on your search page
Definitely a +1 from me on Chromatic's suggestion, which made your intention much clearer to me.
It is wise to encapsulate actions as suggested and I would also urge you to review the way you are managing the HTML. If you decide at some point in the future to modify the HTML output, then you've got a bug maintenance/consistency problem.
My principle is that if I start copying and pasting bits of code then it needs to be extracted and made a subroutine. The first if statement block is similar all the way through with the content variation dependent on the file name. The second block, aka the else block, differs but is presumably still a function of the file + some other component.
So I'd take chromatic's code and add in
sub fn1 { my ($fh, $ucsearch ) = @_; my $count = 0; while (my $record = <$fh>) { next unless uc($record) =~ /$ucsearch/; print $record; $count++; } return $count; } ## data is a reference to an array of hashes data structure containing ## the full file name, the file basename, title, and something that + helps decide what you are going to print if the file doesn't open. ## setdata is a subroutine which creates and fills the data structure, + then returns a reference to it ## hint: look the core module File::Basename (http://perldoc.perl.or +g/File/Basename.html) to extract the file basename my $data=setdata(); foreach my $datum (@$data) ( if (open(my $fh, $prestring.$data->{'filename'}) { print "<center><img border=0 src=/article_separator.png><br>< +B>".$data->{'basename'}.":".$data->{'title'}."</B></center><br>"; fn1($fh,$ucsearch); } else { ## print according to the characteristic that decides if the fil +e has no ATOCI or does not exist } }
That helps with maintaining the HTML a little. It would be better to then look at HTML::Template, (which has a tutorial here), for a way to separate your HTML from your code.
In reply to Re^2: losing html in print calling function.
by LesleyB
in thread losing html in print calling function.
by Librum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |