Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
sub new { my ($class, $self) = @_; unless (&work($self) || &sleep($self)) { $self->smoke; $self->cancer_probablity += rand(0.001); } bless ($self, undef); }
Surely you meant:
sub new { my ($class, $self) = @_; unless ($self->work() || $self->sleep()) { $self->smoke; $self->cancer_probablity += rand(0.001); } bless ($self, undef); }
This reads better to me:
unless I go to work, or I got to sleep....

My auto-biography in perl poetry would be a lot longer:

package Jarich; use strict; sub new { my ($class) = @_; bless ({}, $class); } sub freeload { my @needs = qw/money clothes shoes money books computers games bedding sleep time food/; print "Mum/Dad I need more ", $needs[rand(@needs)], "\n"; } sub annoy_parents { my @actions = ("hit sister", "kick dog", "whine", "whine", "whine", "need more", "beg", "borrow", "steal", "go out with a dag"); print $actions[rand(@actions)], "\n"; print $actions[rand(@actions)], "\n"; } sub live { my $self = shift; my @actions = ("drink", "cycle", "play", "paint", "eat"); # fun stuff on weekends. if(rand(7) <= 2) { print $actions[rand(@actions)], " "; $self->{cancer_probablity} += rand(0.0001); } else { $self->work(); } $self->sleep(); } sub work { print "bored bored bored bored bored: ke-ching! Money++"; } sub sleep { print "ZZZZZzzzzzzzzzzzzzzzzzzz\n"; } sub die { my $self = shift; if(rand(100) < 2) { return 1; } elsif($self->{cancer_probability} > 100) { return 1; } return 0; } #======================================================== package Main; my $jarich = new Jarich; my $age = 0; until ($age++ > 18) { $jarich->freeload() && $jarich->annoy_parents(); } until ($jarich->die()) { $jarich->live(); $age++; } print "RIP jarich. 1978-", 1978+$age, "\n";
But that's because I'm a pedant, and insist on code that does stuff. :) (My own version has moved all the arrays out of the functions and into the object but that doesn't look as nice.)

jarich


In reply to Re: Time to buy some pills by jarich
in thread Time to buy some pills by smitz

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 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?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found