in reply to Re^3: OOP - Constant Vs. Subroutine
in thread OOP - Constant Vs. Subroutine

Not really, Class->constant won't inherit from Superclass->constant ; it needs to be defined in both.

however $classObject->constant will inherit constants from superclass as class object methods , and allow the ability to override

so...

package aaa; use constant HELLO=> 'world'; use constant PUNCTUATION=> '!'; sub new { #std constructor here } package bbb; our @ISA= qw( aaa ); use constant HELLO=> 'universe'; package main; my $a= aaa->new(); my $b= bbb->new(); print "\n Hello " . $a->HELLO . $a->PUNCTUATION ; print "\n Hello " . $b->HELLO . $b->PUNCTUATION ;

will get you

Hello world! Hello universe!

but bbb->PUNCTUATION doesn't exist

Replies are listed 'Best First'.
Re^5: OOP - Constant Vs. Subroutine (super constant!)
by tye (Sage) on May 12, 2007 at 18:38 UTC
    but bbb->PUNCT­UATION doesn't exist

    Did you try it?

    package aaa; use constant HELLO=> 'world'; use constant PUNCTUATION=> '!'; package bbb; our @ISA= qw( aaa ); use constant HELLO=> 'universe'; package main; print "\n Hello ", aaa->HELLO(), aaa->PUNCTUATION(); print "\n Hello ", bbb->HELLO(), bbb->PUNCTUATION();

    produces:

    Hello world! Hello universe!

    - tye        

      I had a typo in my ISA when I tried it ( i used isa aaaa ), giving me an inheritance error. You are most certainly correct.