Date sent: Thu, 13 Mar 2008 18:06:27 +0530 From: "Sharan Basappa" <[EMAIL PROTECTED]> To: beginners@perl.org Subject: functions: rotate and factorial
> Hi, > > I was wondering if perl has support for the following operators or functions: > > - rotate: the elements of a given array are shifted such the elements > are shifted right or left > and the last/first element fill the first/last position depending on > whether shift right or shift left is > done. right @a = (pop(@a), @a); left @a = (@a[1..$#a], $a[0]); there's nothing preventing you from moving those to subroutines, eg. like this: sub shiftR (\@) { my ($a) = @_; @$a = (pop(@$a), @$a); return; } sub shiftL (\@) { my ($a) = @_; @$a = (@{$a}[1..$#$a], $a->[0]); return; } @a = (1,2,3,4); print join(',', @a), "\n"; shiftR @a; print join(',', @a), "\n"; shiftL @a; print join(',', @a), "\n"; > - factorial Looks like it's for example in Math::NumberCruncher Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/