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 8617237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:48:28+00:00 2026-06-12T05:48:28+00:00

if I run the next script: use strict; use warnings; sub load { use

  • 0

if I run the next script:

use strict;
use warnings;

sub load {
    use File::Path qw (make_path);
}

load();
make_path('1/2/3/4');

exit 0;

It works perfectly. I would like to limit the scope of a loaded module to the subroutine so that I cannot use subroutines declared in the module outside the subroutine which loads it. Is it possible?

  • 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-12T05:48:30+00:00Added an answer on June 12, 2026 at 5:48 am

    Short answer: No, this is not really possible.

    Long answer: After loading File::Path you can not prevent code from calling File::Path::make_path() but you can sort of limit the scope where it is availabel by the short name.

    use File::Path ();
    
    sub load {
        local *make_path = \&File::Path::make_path;
    
        make_path('foo/bar/baz'); # This would work...
    }
    
    File::Path::make_path('bang/kapow'); # This would work too
    make_path('xyxxy/plugh'); # But this would die
    

    But by using localthe scope is not lexically restricted to the syntactical code block. It is dynamically scoped meaning that all code called by load() would also see make_path as a working subroutine.

    I would recommend against using this technique as it is kind of obscure and can have some hard to explain side effects at a distance. I mostly find it useful for writing unit tests where it might be usable to replace some functions with mock ups.

    The Perl developers are discussing adding lexical subs as part of the language. This feature should allow you to do nearly what you want without the problems of using local. But this is still work in progress and not even available in the development releases of perl.

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

Sidebar

Related Questions

My Perl script needs to run multiple threads simultaneously... use threads ('yield', 'exit' =>
I have the next query that I run via SQLCMD.EXE use [AxDWH_Central_Reporting] GO EXEC
I have a fairly simple block of code. Sub Run(Name) on error resume next
I have a sql script file that I use to install tables, trigger, sequences
use strict; use warnings; use Parallel::ForkManager; my $log = /scripts/downloads/test.log; print Check the $log
I would like to use a single batch file to execute multiple sql in
At work we currently use the following deployment strategy: Run a batch script to
I run next code and I miss somthing, for me it seem OK :
If I run next saturday into strtotime function it shows 4/3/2010 as the date.
When I run my code I'm facing the next 2 errors: mysql_num_rows() expects parameter

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.