Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Scoping problem!!

by cool (Scribe)
on May 10, 2006 at 12:06 UTC ( #548433=perlquestion: print w/replies, xml ) Need Help??

cool has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

1)Let say I am calling another Perl script ( from What is the best way of doin so? I am using "do" at present.

2)What abt the global variable declaration. Will 'our' for a variable in work for as well? What abt 'require' and 'use'.

I am using 5.8.5.

Thank you for your valuable time

Replies are listed 'Best First'.
Re: Scoping problem!!
by blazar (Canon) on May 10, 2006 at 12:09 UTC

    perldoc -f do, perldoc -f require, perldoc -f use. If you ask me, you are better off making a real module, but then if it's really called like that, then don't call it, since the latter already exists and is in core.

    All in all it's hard to suggest you a good strategy without knowing what and really do. For sure what you're asking is awkward, as such, and most people will smell a XY Problem here.

      ... and to add to this excellent advice, take a look at Including files in order to help you solve X
Re: Scoping problem!!
by swampyankee (Parson) on May 10, 2006 at 21:24 UTC

    In regards to question 2:

    "Scoping" applies only within a single program; and are independent programs, so they have no variables in common. The only ways (of which I'm aware) to get information from one to the other are by environment variables (if, for example, is forked from, command line arguments, or some form of interprocess communication, such as pipes.

    As pointed out by the prior respondents, you've got a couple of choices, depending on your application design: re-write as a module (with a nice, descriptive name that does not clobber a core module), rewrite to include the required functionality of, or re-write both to use some form of interprocess communication. This could be as simple as something like ]arguments for] | [arguments for]

    …but probably not.

    update: fixed markup


    "Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. "
    —G. Steele
Re: Scoping problem!!
by ptum (Priest) on May 10, 2006 at 16:44 UTC

    I almost never have two Perl scripts calling each other. In most cases, either:

    • (a) they are integrated closely enough that one (or both) should really be a module, and I end up instantiating one from the other (or a controller script) and calling its methods, or
    • (b) they are independent enough that I have them both talk to a database or a file and trigger them independently by some external event.

    Just my $0.02 worth ...

    No good deed goes unpunished. -- (attributed to) Oscar Wilde

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://548433]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2020-02-22 06:08 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (98 votes). Check out past polls.