Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created May 8, 2012 07:50
Show Gist options
  • Save ynonp/2633347 to your computer and use it in GitHub Desktop.
Save ynonp/2633347 to your computer and use it in GitHub Desktop.
cool zombies
use strict;
use warnings;
use v5.14;
package Zombie;
my $how_many_brainz_i_ate = 0;
sub new {
my $class = shift;
my $x = 0;
my $x_ref = \$x;
bless $x_ref, $class;
return $x_ref;
}
sub eat_brainz {
my ($times) = @_;
$$times += 1;
say "Yummy..." x $$times;
}
package main;
my $bob = Zombie->new;
my $mike = Zombie->new;
$bob->eat_brainz();
$bob->eat_brainz();
$bob->eat_brainz();
$mike->eat_brainz();
use strict;
use warnings;
use v5.14;
package Zombie;
my $how_many_brainz_i_ate = 0;
sub new {
my $class = shift;
my ( $name ) = @_;
my $self = {
name => $name,
size => 0,
};
bless $self, $class;
}
sub eat_brainz {
my $self = shift;
$self->{size} += 1;
printf("%s: %s\n",
$self->{name},
"Yummy..." x $self->{size});
}
package main;
my $bob = Zombie->new('Bob');
my $mike = Zombie->new('Mike');
# output: Bob: Yummy ...
$bob->eat_brainz();
$bob->eat_brainz();
$bob->eat_brainz();
#output: Mike: Yummy ...
$mike->eat_brainz();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment