how to use other file array in program
list.pl
my @array1 = qw ( l2 l3 l4 l5 );
my @array2 = qe ( l6 l2 l3 );
Pgm.pl
use list.pl
print @array1;
is i开发者_如何学Pythont possible ?
try require, require 'list.pl'
.
You might also need to change the scope prefix my
to something more global.
If you need to do something like this, you should setup a module:
List.pm
:
package List;
use Exporter;
our @ISA = 'Exporter';
our @EXPORT = qw(@array1 @array2);
our @array1 = qw(12 13 14 15);
our @array2 = qw(16 12 13);
Pgm.pl
:
use List;
print @array1;
But in general it is better to either code this using fully qualified names (removing the need for Exporter
):
use List ();
print @List::array1;
Or to create an accessor method:
List.pm
:
package List;
my @array1 = qw(12 13 14 15); # my makes these arrays private to this file
my @array2 = qw(16 12 13);
sub array1 {\@array1} # accessor methods provide ways to change your
sub array2 {\@array2} # implementation if needed
Pgm.pl
:
use List;
my $array1 = List->array1;
print @$array1;
精彩评论