Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:08:35+00:00 2026-06-08T23:08:35+00:00

Is it possible to redefine the _function_used_by_exported_function only for the exported_function call in the

  • 0

Is it possible to redefine the _function_used_by_exported_function only for the exported_function call in the second_routine?

#!/usr/bin/env perl
use warnings; 
use strict;
use Needed::Module qw(exported_function);


sub first_routine {
    return exported_function( 2 );
}

no warnings 'redefine';

sub Needed::Module::_function_used_by_exported_function {
    return 'B';
}

sub second_routine {
    return exported_function( 5 );
}

say first_routine();
say second_routine();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:08:37+00:00Added an answer on June 8, 2026 at 11:08 pm

    You can locally redefine the sub _function_used_by_exported_function inside your sub second_routine.

    package Foo;
    use warnings; 
    use strict;
    use base qw(Exporter);
    our @EXPORT = qw(exported_function);
    
    sub exported_function {
      print 10 ** $_[0] + _function_used_by_exported_function();
    }
    
    sub _function_used_by_exported_function {
      return 5;
    }
    
    package main;
    use warnings; 
    use strict;
    
    Foo->import; # "use"
    
    sub first_routine {
        return exported_function( 2 );
    }
    
    sub second_routine {
        no warnings 'redefine';
        local *Foo::_function_used_by_exported_function = sub { return 2 };
        return exported_function( 5 );
    }
    
    say first_routine();
    say second_routine();
    say first_routine();
    

    I lifted the typeglob assignment inside sub second_routine from brian d foy’s Mastering Perl, Chapter 10 on page 161. The sub is redefined by assigning to the typeglob, which only replaces the coderef part of it. I use local to only do that inside the current block. That way, the outside world is not affected by the change, as you can see in the output.

    1051
    1000021
    1051
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to redefine a C# keyword like int to use Int64 instead
Is it possible to redefine a rows name when I use SELECT in MySQL
Is it possible to redefine which object the brackets [] use? I can subclass
Possible Duplicate: Can main function call itself in C++? I found this problem very
Is it possible to redefine the prompt function specified in the user's profile after
As far as I understand JRuby, it is perfectly possible to use Java class
Possible Duplicate: Redefine Built in PHP Functions Howdy! As my servers do not have
Is it possible to redefine class constants (in PHP)? e.g. class B { const
Is it possible to redefine a constant in php which was defined by the
Is it possible to redefine the space width of a tab when printing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.