Re: pushing errors to another sub
[email protected] ("Chas. Owens")
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
On May 14, 2008, at 20:25, Robert Hicks wrote:
> just "bad" pseudo code:
>
> sub one {
> $process->name(\$html) || $errors_from_one( $process->error() );
>
> $process->name(\$text) || $errors_from_one( $process->error() );
> }
>
> sub errors_from_one {
> my $error = @_;
>
> push (my @errors, $error);
>
> # do stuff to make sure the errors are uniq
>
> return my @uniq_error_list;
> }
>
>
> I want to be able to get at those errors later. Will something like
> that work?
>
> Robert
You may be better off creating a set of objects to handle this, but
here is a lightweight solution:
{ #limit visibility of @queue to these two functions
my @queue;
sub save_errors { push @queue, @_; }
sub handle_errors {
for my $error (@queue) {
#do something
}
}
}
sub one {
$process->name(\$html) or save_errors($process->error);
$process->name(\$text) or save_errors($process->error);
}