Hello,
I’ve read this: http://perldoc.perl.org/functions/require.html
and in my example I try to “include” a perl file to another but I get errors:
Global symbol “$var1” requires explicit package name at ./1.pl line 8.
Global symbol “$var2” requires explicit package name at ./1.pl line 9.
Execution of ./1.pl aborted due to compilation errors.
Code of the two files:
1.pl
#!/usr/bin/perl -w
use strict;
require '2.pl';
print $var1;
print $var2;
2.pl
#!/usr/bin/perl -w
my $var1 = "hello";
my $var2 = " perl!";
I’ve also tried these, but every time, I get the same errors:
2.pl
#!/usr/bin/perl -w
local $var1 = "hello";
local $var2 = " perl!";
2.pl
#!/usr/bin/perl -w
our $var1 = "hello";
our $var2 = " perl!";
and
1.pl
#!/usr/bin/perl -w
use strict;
package HelloWorld
require '2.pl';
print $var1;
print $var2;
2.pl
#!/usr/bin/perl -w
package HelloWorld
my $var1 = "hello";
my $var2 = " perl!";
1;
Could somebody explain me these? Is it cause they aren’t in the same scope?
I’ve coded PHP for couple years, and now learning Perl.
Thanks