in reply to basic inheritance question
Two possible fixes:
1. Move the "my $obj" line to the end
; or
2. add an INIT before each block declaring the class like this:
You should also add a "1;" at the end of each class (Although your code works without that).INIT{ package TestClass; ...
Update: Updated code. I find using "use base" more readable and safer than messing with @ISA;
#!/usr/bin/perl use strict; use warnings; my $obj=TestSubClass->new; INIT{ package TestClass; sub new { my $class = shift; my $self = {}; print "I'm brand new!\n"; bless $self, $class; } 1; } INIT{ package TestSubClass; use base "TestClass"; 1; }
Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: basic inheritance question
by ikegami (Patriarch) on Jun 05, 2009 at 02:53 UTC | |
|
Re^2: basic inheritance question
by JavaFan (Canon) on Jun 05, 2009 at 08:12 UTC | |
by NetWallah (Canon) on Jun 05, 2009 at 20:31 UTC | |
by shmem (Chancellor) on Jun 05, 2009 at 21:25 UTC | |
|
Re^2: basic inheritance question
by trwww (Priest) on Jun 05, 2009 at 01:56 UTC | |
|
Re^2: basic inheritance question
by jason_s (Acolyte) on Jun 05, 2009 at 00:40 UTC | |
by ikegami (Patriarch) on Jun 05, 2009 at 02:56 UTC |