...and this may not even be the first homework question asked by lelak.
If you have two programs that you need to communicate between, you need to use the IPC version of open, or backticks (look for the qx// item in perlop).
In many cases like this, where you have two scrips needing to do (in part) the same task, it's usually easier to separate out the common task into a module, and call the module from both scripts. In a pinch, use open or `backticks` and just parse the output returned by the 2nd script. | [reply] [d/l] [select] |
The solution you want really depends on the whole sequence: If your programs run in sequence, first the one that
| [reply] |
Perl has no global variables. It sounds like you may want to look into one of two possibilities...
1 - Have program two call require 'program_one.pl' at some point before it needs to use $total_orange, this technique will allow you to put $total_orange in the main package and use it as you want.
2 (better) - Make program one a seperate package (ie. package Program_one with a function which can be called to calculate and return the desired value. Then program two needs to use Program_one; and run my $total_orange = Program_one::oranges();. This is the more desireable solution because it helps you to learn about files, packages and modules in perl.
| [reply] [d/l] [select] |
Stop that train! Perl has global variables. What you may be thinking is that each package global exists in its own namespace, so $foo in package Foo is a distinct entity from $foo in package Bar. But all that means is that while you're in package Bar, $foo refers to $Bar::foo. A variable declared in a package (with use vars or, in 5.6, our) is global within that package (e.g. every subroutine in that package can see and modify that variable (unless it's masked by a my declaration -- i.e. within a block (or, if used outside of a block, a file), use of $foo will refer to the variable declared with my $foo)
You may have been thinking that under use strict 'vars', you need to declare variables with my before you can refer to them, but that's not really true (e.g. you can use vars -- for the skinny, see strict (even better the man page on your system) or tye's writeup strict.pm)
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
| [reply] [d/l] [select] |
I'm aware that perl has locally global variables.
However I thought the poster referred to globals in VB, which as I
recall if declared in a module can be package globals in
all packages simultaneously. However my recall may be incorrect since I
have seen the light of the holy Perl and left icky VB behind (in other
words I haven't used it for a while). Any way this would mean that
one instance of the global var $foo is
accessible in all packages without using a fully qualified name. This can
be useful for a very common function, status variable or a useful constant.
However perl does not have global globals and that is the question I was answering.
| [reply] |