If I'm reading your code right:
$self->{S_KEY} will be a string.
$shift is how many characters to rotate
If $shift is odd throw away first character
$self->{S_KEY} = substr($self->{S_KEY},1);
To the end of the str is default
If $shift is even throw away last character
Just use chop.
Then shift the first $shift chars to the back
The for loop calaculation is wasteful in that you do that
calculation on every loop. (Unless the compiler optimizes
it, but you're thinking C in construct) You could of done
foreach my $i (0..($shift %length($self->{S_KEY})))
I'm a bit () happy.
Or better yet don't use a loop.
$shift = ($shift % length($self->{S_KEY})
$self->{S_KEY} = substr($self->{S_KEY}, $shift).substr($self->{S_KEY},
+ 0, $shift);
And as
MeowChow points out, what's with the bad prototyping? I forgot
I stripped that out of hand. use strict and turn on warnings
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.