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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:41:31+00:00 2026-05-25T20:41:31+00:00

example out.pl: (my|our|local|global|whatever???) var = test; require(inside.pm); inside.pm: print $var; I don’t want to

  • 0

example

out.pl:

(my|our|local|global|whatever???) var = "test";
require("inside.pm");

inside.pm:

print $var;

I don’t want to use packages – it’s overwhelming my needs 🙂
thanks!

  • 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-05-25T20:41:32+00:00Added an answer on May 25, 2026 at 8:41 pm

    It will work with our.

    $ cat out.pl
    our $var = "test";
    require("inside.pm");
    
    $ cat inside.pm 
    print "Testing...\n";
    print "$var\n";
    
    $ perl out.pl
    Testing...
    test
    

    This works because our makes $var global, and inside.pm is being executed in the scope with $var defined. Not sure it is recommended technique, but it is an interesting question nevertheless!

    EDIT: Need to clarify (okay patch) the answer based on a comment:

    From the documentation on the Perl function our:

    our associates a simple name with a package (read: global) variable in the current package, for use within the current lexical scope. In other words, our has the same scoping rules as my or state, but does not necessarily create a variable.

    So using our, we get $var with the current package (here probably main) and we can use it in its scope. In effect it is then “global” to the code in the file you are requiring-in.

    A true global is introduced without the our, because variables default to global. But I don’t know anyone that would recommend them.

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

Sidebar

Related Questions

I have taken an example straight out of the MSDN. I want to create
I'm looking for a method (or function) to strip out the example.ext part of
Is there any code example teaching how to zoom in and out in a
To give an example of the kind of request that I can't figure out
I'm trying to figure out why the control does not honor ZIndex. Example 1
Is it possible to find out who called a stored procedure? For example, say
Here's an example: Double d = (1/3); System.out.println(d); This returns 0, not 0.33333... as
TryParse family of methods uses out parameters; I could give Swap as an example
I couldn't figure out that from SASS documentation. For example I would like to
is there an out-of-box way to spell out an int in C#? For example

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.