Home  |  Linux  | Mysql  | PHP  | XML
From:Chas. Owens Date:Thu May 15 10:41:18 2008
Subject:Re: pushing errors to another sub
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);
}
Navigate in group perl.beginners at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants