This sounds like you're doing some sort of error-logging and reporting. There are a number of good ways to do this, many of them on CPAN. I'd go take a look there, first.

Secondly, a few general coding suggestions.

my $error = $s->error if ($count > 0); ## log this action &log_action('error') if ($count > 0);
This would be better written as
if ($count > 0) { my $error = $s->error; &log_action('error', $error); }
This way, it's obvious that the two actions take place at the same time. Now, if you never need to use $error again, I would reccomend doing something like
&log_action('error', $s->error) if ($count > 0);
Another thing - your variable names need improvement. Right now, you know what $s and $i do. But, will you in six months? Maybe rewrite log_action() as such
sub log_action { my ($action_type, $string) = @_; if (lc($action_type) eq 'error') { print "\n$string\n\n"; print FH "$format $string\n"; ... }
In addition, I would look at passing the filehandle into the log_action() sub-routine. Maybe, use IO::File to create a reference to a filehandle and pass it around. This way, log_action() knows as little as possible about its world, making it possible to move it around to new scripts you might write. (Maybe, you might even look at putting log_action() into its own module, with a few other error-logging routines?)

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.


In reply to Re: passing a variable from one subroutine to another by dragonchild
in thread passing a variable from one subroutine to another by c

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.