in reply to passing a variable from one subroutine to another
Secondly, a few general coding suggestions.
This would be better written asmy $error = $s->error if ($count > 0); ## log this action &log_action('error') if ($count > 0);
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 likeif ($count > 0) { my $error = $s->error; &log_action('error', $error); }
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&log_action('error', $s->error) if ($count > 0);
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?)sub log_action { my ($action_type, $string) = @_; if (lc($action_type) eq 'error') { print "\n$string\n\n"; print FH "$format $string\n"; ... }
------
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.
|
|---|