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

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.