in reply to Dynamic names
Produces:use warnings; use strict; package Cow; { sub speak { print "Moo\n" } } package Horse; { sub speak { print "Hi, my name is Ed\n" } } package Sheep; { sub speak { print "Baaaah\n" } } my @pasture = qw(Cow Cow Horse Sheep Sheep); foreach my $animal (@pasture) { $animal = (bless \do{my $anon}, $animal); $animal->speak(); }
Moo Moo Hi, my name is Ed Baaaah Baaaah
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dynamic names
by 7stud (Deacon) on Nov 16, 2010 at 21:31 UTC | |
by cdarke (Prior) on Nov 16, 2010 at 21:41 UTC | |
by 7stud (Deacon) on Nov 17, 2010 at 23:08 UTC | |
by cdarke (Prior) on Nov 18, 2010 at 10:22 UTC |