As people may refine and redefine methods within these objects, I have come up with the following way to "refresh" the existing objects on the fly. (The Everything engine uses eval liberally, but that imposes performance constraints I wish to avoid, if at all possible.) Is there a better way than this?
and the Sub.pm file is, initially:#!/usr/bin/perl -w -I"/home/chromatic/perl" use strict; use Sub; my $tester = Sub->new(); $tester->name; { local *OUTPUT; open(OUTPUT, ">>/home/chromatic/perl/Sub.pm") || die "Can't append +: $!\n"; print OUTPUT "\nsub game {\n"; print OUTPUT " print \"Hi, this is the game subroutine.\\n\";\n"; print OUTPUT "}\n"; print OUTPUT "1;"; close OUTPUT || die "Can't close: $!\n"; } require "/home/chromatic/perl/Sub.pm"; $tester = Sub->new; $tester->game;
This seems to work (aside from having extra 1; statements in the code :), but I get "Subroutine ___ redefined" errors. That makes sense... but is there a better way to do it?#!/usr/bin/perl -w package Sub; use strict; sub new { my $class = shift; my $this = {}; $class = ref($class) || $class; bless($this, $class); return $this; } sub name { print "Hi, this is the name subroutine.\n"; } 1;
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |