If your Users module was object oriented, you could simply pass it a reference to a single Error object. Here is how I would handle your example with the Error module:
package Users; use strict; sub new { my ($class,$error) = @_; my $self = { ERRORS => $error, # and maybe even more . . . $fh? }; bless $self, $class; return $self; } sub get_users { my ($self,$fh) = shift; # rest of your sub # oops, an error happened $self->{ERRORS}->add_error('oops','i like vb'); } # rest of your Users module package main; use strict; use Users; use Error; my $ERROR = Error->new(); my $user = Users->new($ERROR); $user->foo(); print $ERROR->generate_errors(); # or maybe even my @stuff = $user->foo() or print $ERROR->generate_errors();
Also, I really should have included this method below in the Error class. I think it's name explains it's function well enough:
package Error; sub clear { my ($self) = @_; $self->{ERRORS} = undef; } # rest of Error module
My original requirements didn't warrant the need for that method, but yours just might.

Jeff

R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--

In reply to (jeffa) 3Re: style for returning errors from subroutines by jeffa
in thread style for returning errors from subroutines by Boldra

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.