Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine


by jimt (Chaplain)
on Oct 10, 2006 at 20:44 UTC ( #577493=poem: print w/replies, xml ) Need Help??

use strict 'no unwrapped candy'; use warnings 'look out for cars'; use constant HOME_BY => '8:00'; use constant CAN_EAT_TONIGHT => 1; sub halloween { my $self = shift; my $costume = shift or die "Can't have Halloween without a costume +!"; $self->put_on($costume) or die "Costume doesn't fit, choose anothe +r one"; my @houses = $self->neighorhood->houses; my $is_dark_out = 0; while ( ! $is_dark_out && @houses ) { my $house = shift @houses; next if $house->owned_by eq 'stranger' || ! $house->light_on; $self->approach($house) or do { warn "House is too scary"; next; } my $rc = $house->knock(); if ($rc =~ /^tr(ick|eat)$/) { $self->candy->add($rc) if $rc->wrapped; } else { push @{ $self->jerks_i_know }, $house; $self->tp($house) unless $self->mom->watching; } $is_dark_out = 1 if $self->watch->time() > HOME_BY && ! $self- +>beg_for_more_time; } $self->approach($self->home) or die "Mommy! I'm lost"; $self->take_off($costume); my $num_eaten = 0; # note - should re-factor into separate method to be portable to o +ther holidays, # but I'm busy eating sweet, sweet chocolate. EAT_CANDY: while (1) { my $piece = shift @{ $self->candy }; $self->eat($piece); $num_eaten++; if ( $self->mom->watching && $num_eaten > CAN_EAT_TONIGHT ) { # note - bug. This method always returns 0. last if ! $self->beg_for_one_more_piece; } } if ($num_eaten > 5) { sleep $self->watch->delta($self->watch->time, "2am"); $self->wake_up; $self->throw_up; goto EAT_CANDY; } if ( @{ $self->candy } ) { goto EAT_CANDY; } return $self->wait_for("christmas candy"); }

Replies are listed 'Best First'.
Re: Perloween
by ikegami (Pope) on Oct 10, 2006 at 22:08 UTC
    Among other things, I find use strict 'no unwrapped candy' weak.
    # No, spaces prevent the use of qw() use strict 'no unwrapped candy'; # No, Using "no" and "use" together is confusing use strict 'no_unwrapped_candy'; # No, that would mean unwrapped candy is allowed. no strict 'unwrapped_candy'; # No, this is a no-op since the default is 'no' for strict stuff. no strict 'wrapped_candy'; # There we go. This is Perl. use strict 'wrapped_candy';

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: poem [id://577493]
Approved by Corion
zentara...oO 1 more reason I prefer Perl to Python is I can't believe how long Python takes to compile, and you can't disable the myriad of tests
[LanX]: so that's where you've been the last two years? Compiling Python?
[zentara]: LanX no! I was learning why Krishna made me into a unicorn. :-)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-03-30 16:47 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (361 votes). Check out past polls.