Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: I wrote some clever code - can the comment "defuse" it? (stab at restructuring)

by dws (Chancellor)
on Jun 17, 2003 at 23:09 UTC ( [id://266675]=note: print w/replies, xml ) Need Help??


in reply to Re: I wrote some clever code - can the comment "defuse" it? (stab at restructuring)
in thread I wrote some clever code - can the comment "defuse" it?

I think the following is much clearer.

Saving the run lengths in a temporary does help readability. The only nit I have with the otherwise good updated version is that it destroys @letter from within an expression. In this case, it's what you want, but it risks a "Hey, what happened to my letters?!?" if someone else tries to reuse the snippet later.

Replies are listed 'Best First'.
Re^3: I wrote some clever code - can the comment "defuse" it? (stab at restructuring)
by Aristotle (Chancellor) on Jun 18, 2003 at 00:39 UTC
    I don't like it either, but the alternative requires an index variable and some math in the index range for a slice, which I find awfully icky. I'm surprised by the number of people who were caught out by the splice though - I use it in similar fashion as I do here pretty frequently, so it's a familiar sight.

    Makeshifts last the longest.

      There are alternatives to either destroying @letters or using an index. Two I can think of off the top of my head are local @letters (unless it's lexical, which it probably is) or a temporary variable (my @l = @letters and change the code to use that instead). I can't say I like using an additional temp var here, but it is another possibility :)

      Alan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://266675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found