#!/usr/bin/perl use warnings; no warnings qw/uninitialized/; use strict; use Data::Dumper; ####################### package Class1; sub new { my $classname = shift; my $self = {@_}; $self->{NAME} = undef unless $self->{NAME}; $self->{AGE} = undef unless $self->{AGE}; bless($self,$classname); return $self; } sub PrintHello { my $this = shift; print "$this->{TITLE}\tHello $this->{NAME}\t$this->{AGE}\n";; } ####################### package Class2; our @ISA = qw(Class1); sub new { my $class = shift; my $self = $class->SUPER::new(@_); $self->{TITLE} = 'This is Class2'; return $self; } ######################## package main; my $max = Class1->new(NAME=>'Someone Else',AGE=>42); my $max2 = Class2->new(NAME => 'MaxKlokan',AGE=>21) ; $max2->PrintHello(); print Dumper $max; print Dumper $max2; exit;
In reply to Re^2: Defining classes and inheritance using packages within a single .pl file, without creating modules
by alw
in thread Defining classes and inheritance using packages within a single .pl file, without creating modules
by MaxKlokan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |