in reply to "Overriding" functions?

#!/usr/bin/perl use strict; use warnings; require "extras.pl"; # (with extras.pl containing:) # sub sub1 { # print "sub1() from extras\n"; # } # 1; sub sub1 { print "sub1() from main\n"; } sub1(); # prints "sub1() from extras"

but what do you mean "I can't use the OO capabilities..."?

Replies are listed 'Best First'.
Re^2: "Overriding" functions?
by ysth (Canon) on Jul 04, 2007 at 17:11 UTC
    Under -w, this gives a redefinition warning. extras.pl should have
    use warnings; no warnings "redefine";
    (or muck about with $^W for the hardcore anti-warnings.pm people).
      use warnings; no warnings "redefine";

      Just to be on the safe side,

      { no warnings "redefine"; sub that_must_be_redefined { ... } }

      If wanting to be very very picky...

      { my $redefined = sub { ... } no warnings "redefine"; *that_must_be_redefined = $redefined; }
Re^2: "Overriding" functions?
by parv (Parson) on Jul 04, 2007 at 21:08 UTC

    By "I can't use the OO capabilities..." I suppose OP meant that s?he cannot use OO style to provide for namespace[0] or polymorphism such that the desired method|function could be called.

    Addendum. [0]A namespace can also be provided for by a non-OO module which does not export the sub in question by default.