require "external_subs.txt";
my $a = 1;
my $b = blue;
if($a == 1) {
&numbers
} else{ die;
That would be the main script file and this would be the external file, "external_subs.txt" :
sub numbers {
print "$b";
}
1;
If you take out the 'my' fuctions, the whole thing works fine as you can see. But put them in and your stuck in my situation. =\
Plankton@Chum_Bucket:~/perl/perlmonks> cat scritp.pl
#!/usr/local/bin/perl
use strict;
require "ex.txt";
my $bb = "blue\n";
&numbers ( $bb );
Plankton@Chum_Bucket:~/perl/perlmonks> cat ex.txt
sub numbers {
my $v = shift;
print "$v"
}
1;
| Plankton: 1% Evil, 99% Hot Gas. |
The problem is fixed by using
our $b = 'blue';
instead of "my".
"An our declaration declares a global variable that will be visible across its entire lexical scope, even across package boundaries. "
Offense, like beauty, is in the eye of the beholder, and a fantasy.
By guaranteeing freedom of expression, the First Amendment also guarantees offense.
&numbers($b);in the main script and
sub numbers {
my $b=shift @_;
print "$b";
}
in your external_subs.txt? That way, it will work with my, and use strict and all the rest
of the stuff that will save you from having your brain fried once your script gets a bit more complex.
perlmonks.org content © perlmonks.org and antioch, matija, NetWallah, Plankton
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03