Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
use strict;
Enable strict mode. There are no errors because of undefined vars because you used $a and $b, which are always defined, as they are used by sorting.
For the same reason, you choose @INC;

map{$a++}('g','r','e','p');
You set $a to 4.

$a=$a-$a--+$a++;
or written a little bit cleaner
$a=$a - $a-- + $a++;

But still rather hard to understand, because of the way auto-in/decrement worksin suffix mode:
What happens is (if I got it right):
$a=$a - $a-- + $a++;
$a is now 3, but 4 is substracted
$a=3 - 4 + $a++;
$a=-1 + $a++;

$a is incremented to 4, but 3 (the old value) is used in the addition
$a= -1 + 3
$a is now 2

$a++;
And now its 3

$b=int(rand($a));
sets $b to a value between 0 and 2.

$b++
increments it by one, so it is now 1, 2, or 3. Used to decide which virtue to print.

map {chomp;@INC=split(/\D/);push(@_,(int($INC$b/$b),
int($INC$b+$a/$b)));}(<DATA>);
Here you map over all elements of the DATA array, doing the following things:
chomp;
remove the line brake at the end of the line
@INC=split(/\D/);
Set @INC, by splitting the current line on non-numeric values, thereby removing all charaters from the stuff in DATA. This made me wonder, because first I thought you where using the characters hidden between the numbers as your data. But, as I then found out, you just tossed me a red herring that I gullibly swalloed.
push(@_,(int($INC$b/$b),int($INC$b+$a/$b)))
Now you modify your data structure. In the DATA-section, you stored the ascii values of each character (multiplied by either 1,2 or 3), like so (using the real characters): LIHamu (and these are NOT the 'L', the 'I', the 'H' etc you can see in the DATA section).
With this code segment, you first get item number $b (and divide by $b, so it is now the real ascii value), then you get $b+$a. As $a is 3, this gets the next value of the selected virtue. The shorter virtues are space-padded at the end.

map{printf("%c",$_)}@_;
Here you finally map over all values of @_, printing the character with the ascii value of $_. A nice way to prevent the much-overused chr. Voila.

Nice work! Especially as it's not just one more japh.

I espcially liked the auto-in/decrement stuff and the wrong track you laid in DATA.

--
#!/usr/bin/perl -w just another perl hacker
print+seek(DATA,$=*.3,@-)?~~<DATA>:$:__DATA__

In reply to Solution: Laziness, Impatience, and Hubris by domm
in thread Laziness, Impatience, and Hubris by grep

Title:
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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (5)
    As of 2019-10-19 04:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?