Hi,
I want to know how can we limit the scope of require function in perl file. I have a perl file and it's importing another file in it using require like this:
# main file is ABC.pl
require "abc.pl"
...
...
I perform some operations and now I want to limit the scope of require...Like if we have an open file function in perl then we also have the corresponding close function in perl. What is the corresponding function in perl for require.
Thanks
9 3710
The only example I can think of is when I was reading about "use integer;" - something to the effect of: -
# MyScript.pl
-
use strict;
-
use warnings;
-
-
{
-
use integer; # In the current scope, all division is integer division
-
print 'Inside the brackets, 7/5 = ', 7/5, "\n";
-
} # Now outside the scope, all division is decimal division
-
print 'Outside the brackets, 7/5 = ', 7/5, "\n";
results in the following output: - Inside the brackets, 7/5 = 1
-
Outside the brackets, 7/5 = 1.4
This suggests to me that the 'use' keyword only applies to the current scope.
I don't believe you can. I believe that you can set the scope of 'use' as Gannon suggests. You might also look at perlfunc
--Kevin
Regarding my response, after reading the perldocs for the integer module, it looks like the scope limitation is specific to this module, and is not a characteristic of the 'use' keyword.
You're trying to do something that seems inherently wrong. When you "require" a file it basically becomes part of the main script. Functions typically have no scope but you can make references to functions that do. You can also use OO programming to give an objects methods a limited scope.
Acutally I want to use 2 different functions with the same name present in 2 different perl files in the 3rd perl file.For this reason I import the 2 files using 'require' in the 3rd perl file.But how does my 3rd perl file knows which function it's calling,it could be the function either from the 1st file or the 2nd file.
Acutally I want to use 2 different functions with the same name present in 2 different perl files in the 3rd perl file.For this reason I import the 2 files using 'require' in the 3rd perl file.But how does my 3rd perl file knows which function it's calling,it could be the function either from the 1st file or the 2nd file.
Sounded similar to what I've asked before. See thread849210 for some good ideas. I ended up keeping the functions with different names.
Perl knows what file the function came from with "use".
All subroutines in the "main" file have the prefix "main", for simplicity this can be ommited. So that:
&main::doIt();
is the same as:
&doIt();
If you "use" a package then the name of that package must be appended,
IE:
use HomemadePackage;
Then &HomemadePackage::doIt();
would not clash with a sunroutine in the main file called doIt(); However with "require" the other file actually gets clobbered into the main package. All variables and subroutines must be carfeully considered.
Really the only reliable way would be to rename the subs.
Although I'm sure there's a workaround.
I followed the thread...and I tried using undef..It dint work.I dont want to use package as that would fit into my requirements. I think I will eventually end up doing the same thing u did,using different subroutine names.
Hi all,
Thank you for all your suggestions. I am using finally a different sub name.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: sam |
last post by:
I have a function writen in Perl that takes a name-value list (array) as
argument
and returns a name-value list (array).
My question is:
How to call this function from PHP and get the returned...
|
by: Hallvard B Furuseth |
last post by:
Now that the '-*- coding: <charset> -*-' feature has arrived,
I'd like to see an addition:
# -*- str7bit:True -*-
After the source file has been converted to Unicode, cause a parse
error if a...
|
by: Michael |
last post by:
Guten Morgen,
I am implementing a script that my client wants on their website. Within
the script there are several "require" statements. Any time one of these
"require" statements is...
|
by: raghavendra |
last post by:
Hi ,
A static member can be accessed only by another static method....but the
vice-versa is not true....Can anyone pls explain me the logic behind this...
Also in a project, if we have too many...
|
by: Allen Landsidel |
last post by:
I have a job-processing backend written in perl, talking to a (of course)
postgres database. The perl app has a master process that checks the
database periodically for jobs that need processed. ...
|
by: kardon33 |
last post by:
I have a Perl Header file i need to include so i can call stuff out of it. Heres my code. The problem in on 8 and 9, when i try to print a variable out of the header file it does not work.
...
|
by: kokul |
last post by:
Hi friends,
I want to call one function depends on a variable. First i set that variable to 0 before the functiobn definition and inside the function i incriment that variable. Then i check...
|
by: thorsten.schilling |
last post by:
Hello everybody,
the question is, what is the "golden way" or the best way, if I have a
memberfunction in a class, which should return a new instance of an
object.
For example some class Foo...
|
by: PeterAPIIT |
last post by:
Hello all C++ expert programmer,
i have wrote partial general allocator for my container.
After reading standard C++ library and code guru article, i have
several questions.
1. Why...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |