#!/usr/bin/env perl use warnings; use strict; { package Basic; use warnings; use strict; use mem; use P; our @flags; use mem (@flags = qw(one two three four five) ); use Data::Vars \@flags, {one=>1, two=>2, three=>3, four=>4, five=>5}; sub Decimal() { my $p=shift; P "\nDecimal:p=%s", $p; my $q=__PACKAGE__->new(); $q->three="change 3 to 33/11"; P "Decimal: (one, two, three)=(%s, %s, %s)", $q->one, $q->two, $q->three; } } { package Derived; use warnings; use strict; use mem; use P; our @ISA; use mem (&{sub() {push @ISA, q(Basic)}}); use Data::Vars [qw(one two seven)], {one=>1.2, two=>2.2, seven=>7.2, eight=>8.2}; sub new ($) { my $p = shift; my $c=$p||ref $p; bless $p = Basic->new(@_), $c unless ref $p; $p = $p->Data::Vars::new($p); } sub Float() { my $p=shift; P "\nFloat:p=%s", $p; my $q=__PACKAGE__->new(); $q->three="Float: 3.3"; $q->four="Float: Derived 4.4"; my $val = eval { $q->nine="Float: 9.9"; }; if ($@) { P "\nassign to nine got:\n%s\n", $@; } P "Float:q=%s", $q; } 1} package main; use warnings; use strict; use P; use Data::Vars [ qw(one three four) ]; bless my $p = __PACKAGE__->new({one=>'I', three=>'III', four=>'IV'}); P "main:1: p=%s", $p; $p = Derived->new($p); P "main:2: %s", $p; $p->Decimal; $p->Float; #### > perl multiuse.pl main:1: p=main{four=>"IV", one=>'I', three=>"III"} main:2: Derived{five=>5, four=>"IV", one=>1.20, seven=>7.20, three=>"III", two=>2.20} Decimal:p=Derived{five=>5, four=>"IV", one=>1.20, seven=>7.20, three=>"III", two=>2.20} Decimal: (one, two, three)=(1, 2, change 3 to this txt) Float:p=Derived{five=>5, four=>"IV", one=>1.20, seven=>7.20, three=>"III", two=>2.20} assign to nine got: Can't locate object method "nine" via package "Derived" at multiuse.pl line 37. eval {...} called at multiuse.pl line 37 Derived::Float(Derived=HASH(0x8e5648)) called at multiuse.pl line 56 Float:q=Derived{five=>5, four=>"Float: Derived 4.4", one=>1.20, seven=>7.20, three=>"Float: 3.3", two=>2.20}