Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Make it a habit to review old code, It'll do your code and your coding expertise good.

Indeed! This doesn't just apply to copy and paste either, as I often find things that can be done better or simply coded more clearly when I pull out some little program I wrote 6 months ago. I take the fact that I'm using it a second time as a sign that a little more investment of effort could well pay off in the future. Recently I have found myself replacing silly little loops with map or grep (as appropriate) and finding the clarity of the code improves significantly.

On your specific example, you could go a step farther and eliminate the multiple sprintf calls. On my box (Win95, ActiveState 628) this appears to be 20% faster than the array improvement alone:

sub zeit_mit_Albannach { # new function calling sprintf only once my @zeit = localtime; my $wtag = ("So","Mo","Di","Mi","Do","Fr","Sa")[$zeit[6]]; sprintf("$wtag %02d.%02d.%4d - %02d:%02d", $zeit[3], $zeit[4]+1, $zeit[5] + 1900, $zeit[2], $zeit[1]); }

--
I'd like to be able to assign to an luser


In reply to Re: old code revisited by Albannach
in thread old code revisited by neophyte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-08-09 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?