print foo(3); sub foo { $a = shift; if ($a == 1) { return 1; } else { $a * foo($a-1) } } |
#!/usr/bin/perl use IT; it = IT->new(); $y = 2; it->twinky(3); it->dingdong(5) |
package IT; sub new { my($class) = shift; bless { $x => 0 }, $class; } sub twinky { my($self) = shift; $y = 12; $self->{"x"} = 17; } sub dingdog { my($self) = shift; print $self->{"x"} . " = $y\n"; } |
#!/usr/bin/perl -w $a = Max->new(); print "Enter a doctor's age, or ^D to quit\n"; while($line = <STDIN>) { $a->newValue($line); } print "The max age is :"; print $a->getMax(); print " and that's old!\n"; |