Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
He's going to fight to the last against doing something 'childish', even though I assure him that when I'm coding professionally I'm doing little test scripts more than I'm working on the 'real' program.

Right on, jepri! I just had a quick scan on 4 different accounts here at work, that reveals some 400+ little test scripts. On each machine I have a ~/perl directory where I try out snippets to check how things work. For instance, the other day I had hesitations about how splice works, because I use it so rarely. So I whipped up "muncharr" which looks like:

#! /usr/bin/perl -w use strict; my @arr = ('a'..'z'); my $nr = shift || 6; local $, = ' '; while( scalar @arr ) { my @block = splice( @arr, 0, $nr ); print "@block\n"; }

With that, I was able to see straight away that my understanding of how splice worked was in line with reality. It took me about 2 minutes for take the time out to perldoc -f splice and test this out. I was then able to fold the principle back into my main code and safe in the knowledge that at least that part of the code was likely to be bug-free :)

And I suppose it is useful to stress that even little snippets are deserving of strict and -w. Also note how I wrote the script to use default value(s) that can be overriden from the command line.

print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: Adult learning problem by grinder
in thread Adult learning problem by jepri

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

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (9)
    As of 2020-11-25 14:46 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found