Well, I'd probably help my user by catching some coding mistakes rather than letting them cause strange behavior that they'd have to spend much more time debugging:

sub method { my $self= shift(@_); croak 'Usage: $oldVal= $obj->method( $idx [, $newVal ] )',$/ unless 1 <= @_ && @_ <= 2; my $i= shift(@_); my $old= $self->{B}[$i]; $self->{B}[$i]= shift(@_) if @_; return $old; }
But I don't like the magic numbers there so I might avoid them at the cost of some duplication but with even better error messages:
sub method { my $self= shift(@_); croak 'Missing $idx; usage: $oldVal= $obj->method( $idx [, $newVal + ] )',$/ unless @_; my $i= shift(@_); my $old= $self->{B}[$i]; $self->{B}[$i]= shift(@_) if @_; croak 'Too many args; usage: $oldVal= $obj->method( $idx [, $newVa +l ] )',$/ if @_; return $old; }
Then you can remove some duplication with:
{ my $usage; BEGIN { $usage= '$oldVal= $obj->method( $idx [, $newVal ] )' } sub method { my $self= shift(@_); croak "Missing \$idx; usage: $usage\n" unless @_; my $i= shift(@_); my $old= $self->{B}[$i]; $self->{B}[$i]= shift(@_) if @_; croak "Too many args; usage: $usage\n" if @_; return $old; } }

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Very very small style question by tye
in thread Very very small style question by Dominus

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.