[ create a new paste ] login | about

Link: http://codepad.org/n1zR8zRZ    [ raw code | output | fork ]

Perl, pasted on Jul 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/local/bin/perl                                                           
use strict;
use warnings;
{
    package Animal;
    sub new { bless {}, shift }
    package Cat;
    use base 'Animal'; # inherits new()                                         
    sub speak { print "meow!\n" }
    package Dog;
    use base 'Animal'; # inherits new()                                         
    sub speak { print "woof!\n" }
}

$_->speak for map { $_->new } qw/Cat Dog/;
speak $_  for map { new $_ } qw/Cat Dog/;


Output:
1
2
3
4
meow!
woof!
meow!
woof!


Create a new paste based on this one


Comments: