in reply to Re: how to import a module var
in thread how to import a module var

hi, i already used the Exporter but still my prog cant access the arra +y in the module. Here is my module : package Voucher; use strict; use warnings; require Exporter; our @ISA = qw /Exporter/; our @EXPORT_OK = qw /@LIST @RANGE1 @RANGE2 @RANGE3 @RANGE4 @RANGE5 @RA +NGE6/; sub new { my ($class) = @_; my $self = { _loadSch => undef, _loadRanges => undef }; bless $self,$class; return $self; } sub loadSch { my ($self,$loadSch) = @_; my $schdir="./D_sch_folder/"; opendir(SCH,$schdir) || die "Error::Cannot load Sch Directory!!!\n +"; my @sch=grep(/[dD]_[sS][cC][hH].txt/,readdir(SCH)); my $schlist = $schdir.$sch[0]; open (IN,"$schlist") || die "Error::Cannot open Sch list!!!\n"; print "Loading d_sch.txt . . .\n\n"; our @LIST=<IN>; my $c=@LIST; print "$c\n"; sleep 1; } sub loadRanges { my ($self,$loadRanges) = @_; my $rangedir = "./number ranges/"; my $loadCTU7 = $rangedir."CTU7_range.txt"; my $loadTU7 = $rangedir."TU7_range.txt"; my $loadCTU30= $rangedir."CTU30_range.txt"; my $loadTU30 = $rangedir."TU30_range.txt"; my $loadDIAZ = $rangedir."DIAZ_ranges.txt"; my $loadIDD = $rangedir."IDD_range.txt"; open(R1,"$loadCTU7") || die "Error::Cannot load CTU7 ranges!!!\n"; open(R2,"$loadTU7") || die "Error::Cannot load TU7 ranges !!!\n"; open(R3,"$loadCTU30") || die "Error::Cannot load CTU30 ranges!!!\n +"; open(R4,"$loadTU30") || die "Error::Cannot load TU30 ranges!!!\n"; open(R5,"$loadDIAZ") || die "Error::Cannot load DIAZ ranges!!!\n"; open(R6,"$loadIDD") || die "Error::Cannot load IDD ranges!!!\n"; print "Loading E-Mongolia Card Ranges . . .\n\n"; my @RANGE1=<R1>; my @RANGE2=<R2>; my @RANGE3=<R3>; my @RANGE4=<R4>; my @RANGE5=<R5>; my @RANGE6=<R6>; sleep 1; } 1; <br> and here is my code: #! /usr/perl/bin/perl use warnings; use lib qw (./modules); use Voucher; $vouch=Voucher->new(); $vouch->loadSch(); # load d_sch.txt $vouch->loadRanges(); # load ranges $count=$pro1=$pro2=$pro3=$pro5=$pro6=$pro7=$pro8=$pro19=$pro20=$pro21= +$pro22=$pro23=$pro24=$pro25=$pro27=0; $l=@LIST; print "$l\n"; foreach $in (@LIST){ if ($in=~/^922/){ chomp($in); print "$in\n"; @a=split(/\s+/,$in); if ($a[4] eq "PROFILE1"){ $pro1++; $count++; } elsif ($a[4] eq "PROFILE2"){ $pro2++; $count++; } elsif ($a[4] eq "PROFILE3"){ $pro3++; $count++; } elsif ($a[4] eq "PROFILE5"){ $pro5++; $count++; } elsif ($a[4] eq "PROFILE6"){ $pro6++; $count++; } elsif ($a[4] eq "PROFILE7"){ $pro7++; $count++; } elsif ($a[4] eq "PROFILE8"){ $pro8++; $count++; } elsif ($a[4] eq "PROFILE19"){ $pro19++; $count++; } elsif ($a[4] eq "PROFILE20"){ $pro20++; $count++; } elsif ($a[4] eq "PROFILE21"){ $pro21++; $count++; } elsif ($a[4] eq "PROFILE22"){ $pro22++; $count++; } elsif ($a[4] eq "PROFILE23"){ $pro23++; $count++; } elsif ($a[4] eq "PROFILE24"){ $pro24++; $count++; } elsif ($a[4] eq "PROFILE25"){ $pro25++; $count++; } elsif ($a[4] eq "PROFILE27"){ $pro27++; $count++; } } } print "$count\n";

Replies are listed 'Best First'.
Re^3: how to import a module var
by Perl Mouse (Chaplain) on Nov 22, 2005 at 13:50 UTC
    You make some variable potentially available by listing them in @EXPORT_OK, but you never import then when using the module. Either make the variable available by default, using @EXPORT instead of @EXPORT_OK, or tell the import routine which variables you want, by listing them in the use statement.

    And next time, don't post a gazillion lines - you could have written a short example with the same problem.

    Perl --((8:>*
Re^3: how to import a module var
by Anonymous Monk on Nov 22, 2005 at 13:27 UTC
    You need to perldoc Exporter