Hi,
I hope someone can help me as I am completely lost. The platform is Windows.
I have a main.pl that will read in records from a file and print the customer numbers. I created a separate .pl that has common subroutines that will be used other Perl scripts. One subroutine defines the record fields, the other parses the input record.
The fields defined in the called subroutines are not accessible to the main.pl. Also, I don't think the record input is accessible to the called parsing subroutine.
I tried reading about packages, export/import but cannot get a clear understanding of it.
Any assistance will be greatly appreciated!!
Below are the main, external module and execution error.
Main.pl:
#
#-----------------------------------------------------------
# Set variables
#-----------------------------------------------------------
#
use warnings;
use strict;
my $dir = 'e:\test';
my $INFILE = "$dir/INFILE";
my $rec;
require "./include/INCL_test.pl";
#-----------------------------------------------------------
# Open files
#-----------------------------------------------------------
#
open (INFILE, "< $INFILE") or die print "Cannot open input file \n";
#----------------------------------------#
# file fields
#----------------------------------------#
#
defn_fields;
#----------------------------------------#
# Main routine
#----------------------------------------#
#
while ($rec = <INFILE>) {
chomp $rec;
$rec=~s/\"//g;
parse_rec;
print "Customer number $CUST_NO \n";
}
close (INFILE);
print "END OF SCRIPT \n";
exit;
#
# end of job
#
This has the common subroutines:
INCL_test.pl:
#----------------------------------------#
# file fields
#----------------------------------------#
#
#there are other fields but just defined one until it works
sub defn_fields {
our $CUST_NO;
}
#-----------------------------------------------------------
# Parse thru input fields
#-----------------------------------------------------------
#
sub parse_rec {
$CUST_NO = substr($rec,0,19);
}
1;
ERRORS:
STEP_010 Execute
Global symbol "$CUST_NO" requires explicit package name at E:\test\subtest.pl line 36.
Bareword "defn_fields" not allowed while "strict subs" in use at E:\test\subtest.pl line 24.
Bareword "parse_fields" not allowed while "strict subs" in use at E:\test\subtest.pl line 34.
Execution of E:\test\subtest.pl aborted due to compilation errors.
STEP_010 Completed.
I hope someone can help me as I am completely lost. The platform is Windows.
I have a main.pl that will read in records from a file and print the customer numbers. I created a separate .pl that has common subroutines that will be used other Perl scripts. One subroutine defines the record fields, the other parses the input record.
The fields defined in the called subroutines are not accessible to the main.pl. Also, I don't think the record input is accessible to the called parsing subroutine.
I tried reading about packages, export/import but cannot get a clear understanding of it.
Any assistance will be greatly appreciated!!
Below are the main, external module and execution error.
Main.pl:
#
#-----------------------------------------------------------
# Set variables
#-----------------------------------------------------------
#
use warnings;
use strict;
my $dir = 'e:\test';
my $INFILE = "$dir/INFILE";
my $rec;
require "./include/INCL_test.pl";
#-----------------------------------------------------------
# Open files
#-----------------------------------------------------------
#
open (INFILE, "< $INFILE") or die print "Cannot open input file \n";
#----------------------------------------#
# file fields
#----------------------------------------#
#
defn_fields;
#----------------------------------------#
# Main routine
#----------------------------------------#
#
while ($rec = <INFILE>) {
chomp $rec;
$rec=~s/\"//g;
parse_rec;
print "Customer number $CUST_NO \n";
}
close (INFILE);
print "END OF SCRIPT \n";
exit;
#
# end of job
#
This has the common subroutines:
INCL_test.pl:
#----------------------------------------#
# file fields
#----------------------------------------#
#
#there are other fields but just defined one until it works
sub defn_fields {
our $CUST_NO;
}
#-----------------------------------------------------------
# Parse thru input fields
#-----------------------------------------------------------
#
sub parse_rec {
$CUST_NO = substr($rec,0,19);
}
1;
ERRORS:
STEP_010 Execute
Global symbol "$CUST_NO" requires explicit package name at E:\test\subtest.pl line 36.
Bareword "defn_fields" not allowed while "strict subs" in use at E:\test\subtest.pl line 24.
Bareword "parse_fields" not allowed while "strict subs" in use at E:\test\subtest.pl line 34.
Execution of E:\test\subtest.pl aborted due to compilation errors.
STEP_010 Completed.