On Mon, 01 Jul 2002 14:57:36 +0000, sara starre wrote:

>Unfortunately I can't get your solution to work:
>
>  DB<1>
>main::r2(./x.pl:66):           $_ [0] %= @{$_ [1]};
>  DB<1>
>Modification of a read-only value attempted at ./x.pl line 66.

>Seems it doesn't like you trying to modify $_ [0] ?

Then make a copy. The intention isn't to alter the original parameter,
so don't do that.

In order to stay within the current state of obfuscation, choosing $_ as
a temporary variable for the copy looks just right:     ;-)

        local $_ = $_[0] % @{$_[1]};
        return  [@{$_ [1]} [$_  .. $#{$_ [1]}, 0 .. $_ - 1]]

>Also will yours work 
>with negative rotation like rotate(-3, \@a) ?

That's the idea behind using the % operator anyway.

        print -3 % 10;
-->
        7

>also
>
>  return [] unless @{$_ [1]};
>
>give a runtime error if $_[1] isn't an array ref- seems like you'd want to 
>find another way to trap that error as you're trying to AVOID errors with 
>that statement?

Eh... sorry? Using anything but an array ref looks like an error in your
source code. It *should* barf. However, preferably, the error message
ought to point to your calling statement, not the sub itself. Using
croak(), from the module Carp, plus a test on (ref($_[1])eq 'ARRAY')
should do. (Note that for Carp to work well, that your sub should be in
a different package, a different source file (module), or both.)

-- 
        Bart.

Reply via email to