It is clear what you're shifting: an unqualified 'shift' shifts off the
current argument list (in all cases). Writing the @_ explicitly simply
causes someone who knows Perl to have to do a double-take and verify
that the code is in fact shifting @_.
I also use single-space indents, do I have to change that too? I
really think you and Anno are nit-picking style here. Please let me
write out "shift @_". It amuses me and harms no one.
putting every parameter on its own line with its own bit of '= shift
@_;' boilerplate makes it much harder to see what the function is
actually doing.
Well, I guess we'll have to disagree on this. Let's drop it, please.
Efficiency has nothing to do with it: Anno's version is much clearer.
You've got to be kidding. It mashes map without a clear code block
demarcation, uses a range with a recalculated end point on the fly,
and doesn't use return. All in a single line. I'm not criticing
*Anno's code*, just pointing out that for that to be clearer than my
while/push/return code *to a beginner*, you'd have to be on several
medications, none sold over the counter.
I would perhaps agree that for a beginner who has some experience
with C-like or Pascal-like languages an explanation of what map does
in terms of a loop might be helpful, but if we wish to teach people
to write Perl as opposed to C-as-a-subset-of-Perl then this is a
very good example of when map makes things substantially
simpler. (Not that there's anything *wrong* with writing
C-as-a-subset-of-Perl if that's all someone is prepared or able to
learn, but I would have thought that in this group we should be
encouraging people to learn to use Perl properly. Otherwise they'll
never love it
.)
I think Anno's code is clever, correct, fun, but not something I'd
want to see in a production environment or shown to a beginner.
I think you and many posters here like clever code that accomplishes
several things in one shot. That's great, but please don't push that
on beginners who don't yet know what an anonymous code block does.
Please don't assume it's "proper" Perl, either. It's fine Perl, but
as we all know there is no "proper" way to do things in Perl,
TMTOWTDI.
I noticed mine is buggy, I forgot to check that $inc is greater than
zero. It will loop forever otherwise. Sorry about that. Anno's code
will just die if $inc is zero, which is definitely nicer to the user.
Ted