>From: Abigail <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED], [EMAIL PROTECTED]
>Subject: Re: Maybe-useful subroutine
>Date: Mon, 1 Jul 2002 07:25:43 -0700
>
..
..
..
>
>Eeew. That's so horribly inefficient and unPerllike.
>
>Try this:
>
> sub rotate {
> return () unless $_ [1];
> return [] unless @{$_ [1]};
> $_ [0] %= @{$_ [1]};
> [@{$_ [1]} [$_ [0] .. $#{$_ [1]}, 0 .. $_ [0] - 1]]
> }
>
>
>Abigail
Hi Abigail:
I defintely like your syntax better, and yes I was trying to avoid the loop
entirely. 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.
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<1>
Seems it doesn't like you trying to modify $_ [0] ? Also will yours work
with negative rotation like rotate(-3, \@a) ?
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?
Nice work I'd like to see this function. I hate looping but I couldn't see
how to avoid it in this case with the negative possiblities plus the fact
that the rotation parameter can exceed the array length- ie:
my @a=qw(A B C);
rotate(-14, \@a);
PG
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com