jamar49
asked on
How to correct Perl Input file error?
After running the following command:
perl splitfiles.pl -i SSTEST*.txt -c test.conf -e error.txt -r report.txt
I get the following error at 1ine 132:
Unable to open SSTEST*.txt at splitfiles.pl line 132.
Below are lines 130, 131, 132 and Configuration Section
line 130 # open files
line 131 my $input_fh; # *test+1 9/11 206168
line 132 open($input_fh, "<", $INPUT_FILE) or die "Unable to open $INPUT_FILE";
File pattern which needs to split are SSTEST.5 digits.9 digits.YYYYMMDD.835
# Configuration Section
# The users can define defaults that they want to use
$INPUT_FILE = "test.txt";
$ERR_OUTFILE = "error.txt";
$CONFIG_FILE = "remit.conf";
$ORPHAN_FILE = "orphan.txt";
Also I need to run this from crontab.
perl splitfiles.pl -i SSTEST*.txt -c test.conf -e error.txt -r report.txt
I get the following error at 1ine 132:
Unable to open SSTEST*.txt at splitfiles.pl line 132.
Below are lines 130, 131, 132 and Configuration Section
line 130 # open files
line 131 my $input_fh; # *test+1 9/11 206168
line 132 open($input_fh, "<", $INPUT_FILE) or die "Unable to open $INPUT_FILE";
File pattern which needs to split are SSTEST.5 digits.9 digits.YYYYMMDD.835
# Configuration Section
# The users can define defaults that they want to use
$INPUT_FILE = "test.txt";
$ERR_OUTFILE = "error.txt";
$CONFIG_FILE = "remit.conf";
$ORPHAN_FILE = "orphan.txt";
Also I need to run this from crontab.
ASKER
File pattern which needs to split are SSTEST.5 digits.9 digits.YYYYMMDD.835 with that being said should convert .835 to .txt then run perl script
ASKER
There isn't anything else that starts SSTEST that I don't want to split
Is there any other place where $INPUT_FILE is set?
$INPUT_FILE = "test.txt";
open($input_fh, "<", $INPUT_FILE) or die "Unable to open $INPUT_FILE";
would not produce the message
Unable to open SSTEST*.txt at splitfiles.pl line 132.
$INPUT_FILE = "test.txt";
open($input_fh, "<", $INPUT_FILE) or die "Unable to open $INPUT_FILE";
would not produce the message
Unable to open SSTEST*.txt at splitfiles.pl line 132.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
permission is 775
Hereare other places where $INPUT_FILE is set:
# Configuration Section
# The users can define defaults that they want to use
$INPUT_FILE = "test.txt";
sub usage {
print "Usage: $0 [-c configuration file] [-i <Input file>] [-e <error file>] [-r <reporting file>] [-s 0] [-f 1] [-o <orphaned claims>] [-d <detailed report>] [-rc <report by check>] [-p <split by payor>] [-n 1] [-sc <allow check type switch>] \n"; #*BJK 1/10 167916
exit(1);
}
if (@ARGV>0) { # process command-line arguments
my $i;
if ((@ARGV % 2) != 0) { usage()}; # error out if the number of arguments is odd
for ($i=0; ($i<@ARGV+0);) {
if ($ARGV[$i] eq "-c") {
$i++;
$CONFIG_FILE = $ARGV[$i++];
} elsif ($ARGV[$i] eq "-i") {
$i++;
$INPUT_FILE = $ARGV[$i++];
# read the config file and return the number of lines
sub readconfig {
my $confFile = shift();
my $line = 0;
my $index = 0;
my @timelist = localtime;
my $Time = sprintf("%02d", ($timelist[4]+1)).sprintf( "%02d", $timelist[3]).sprintf("%02 d", ($timelist[5]-100)).sprint f("%02d", $timelist[2]).sprintf("%02 d", $timelist[1]);
my $TimeWSec = sprintf("%02d", ($timelist[4]+1)).sprintf( "%02d", $timelist[3]).sprintf("%02 d", ($timelist[5]-100)).sprint f("%02d", $timelist[2]).sprintf("%02 d", $timelist[1]).sprintf("%02 d",$timeli st[0]);
my $ExtTime = sprintf("%04d", ($timelist[5]+1900)).sprin tf("%02d", ($timelist[4]+1)).sprintf( "%02d", $timelist[3]).sprintf("%02 d", $timelist[2]).sprintf("%02 d", $timelist[1]).sprintf("%02 d", $timelist[0]);
my $conf_fh; # *test+1 9/11 206168
open($conf_fh, "<","$confFile") or die("readconfig: unable to open $confFile");
my @elms = split("/", $INPUT_FILE);
my $input_file = $elms[$#elms];
Hereare other places where $INPUT_FILE is set:
# Configuration Section
# The users can define defaults that they want to use
$INPUT_FILE = "test.txt";
sub usage {
print "Usage: $0 [-c configuration file] [-i <Input file>] [-e <error file>] [-r <reporting file>] [-s 0] [-f 1] [-o <orphaned claims>] [-d <detailed report>] [-rc <report by check>] [-p <split by payor>] [-n 1] [-sc <allow check type switch>] \n"; #*BJK 1/10 167916
exit(1);
}
if (@ARGV>0) { # process command-line arguments
my $i;
if ((@ARGV % 2) != 0) { usage()}; # error out if the number of arguments is odd
for ($i=0; ($i<@ARGV+0);) {
if ($ARGV[$i] eq "-c") {
$i++;
$CONFIG_FILE = $ARGV[$i++];
} elsif ($ARGV[$i] eq "-i") {
$i++;
$INPUT_FILE = $ARGV[$i++];
# read the config file and return the number of lines
sub readconfig {
my $confFile = shift();
my $line = 0;
my $index = 0;
my @timelist = localtime;
my $Time = sprintf("%02d", ($timelist[4]+1)).sprintf(
my $TimeWSec = sprintf("%02d", ($timelist[4]+1)).sprintf(
my $ExtTime = sprintf("%04d", ($timelist[5]+1900)).sprin
my $conf_fh; # *test+1 9/11 206168
open($conf_fh, "<","$confFile") or die("readconfig: unable to open $confFile");
my @elms = split("/", $INPUT_FILE);
my $input_file = $elms[$#elms];
Most unix shells would expand SSTEST*.txt on the command line to a list of file names matching that pattern, unless no matching file names are found.
And if more than one matching file names are found, it does not appear that the for ($i=0; ($i<@ARGV+0);) { loop would process them sensibly, though it is hard to be sure, since it also seems to have missing close }
And if more than one matching file names are found, it does not appear that the for ($i=0; ($i<@ARGV+0);) { loop would process them sensibly, though it is hard to be sure, since it also seems to have missing close }
ASKER
Ozo I understand that and I should have said in the being that script will work as long as I use the following :
perl splitfiles.pl -i SSTEST.5 digits.9 digits.YYYYMMDD.835 -c test.conf -e error.txt -r report.txt
But I was trying to use a wildcard because there will be multiple files and each file will have a different "5 digits.9 digits.YYYYMMDD" and I want automate script to run in cron.
perl splitfiles.pl -i SSTEST.5 digits.9 digits.YYYYMMDD.835 -c test.conf -e error.txt -r report.txt
But I was trying to use a wildcard because there will be multiple files and each file will have a different "5 digits.9 digits.YYYYMMDD" and I want automate script to run in cron.
I see where the for loop would set $INPUT_FILE to "SSTEST.5" but I don't see what would be done with digits.9 digits.YYYYMMDD.835
What would different "5 digits.9 digits.YYYYMMDD" look like?
What would different "5 digits.9 digits.YYYYMMDD" look like?
ASKER
file pattern "SSTEST.5 digits.9 digits.YYYYMMDD.835" examples are
SSTEST.12345.123456789.201 31210.835 or SSTEST.12345.12345m789.201 31210.835 or
SSTEST.12345.000056789.201 31210.835 and so fore.
The actual command would look like this:
perl splitfiles.pl -i SSTEST.12345.000056789.201 31210.835 -c test.conf -e error.txt -r report.txt
SSTEST.12345.123456789.201
SSTEST.12345.000056789.201
The actual command would look like this:
perl splitfiles.pl -i SSTEST.12345.000056789.201
You might use
perl splitfiles.pl -i SSTEST.[0-9][0-9][0-9][0-9 ][0-9].[0- 9][0-9][0- 9][0-9][0- 9][0-9][0- 9][0-9][0- 9].[0-9][0 -9][0-9][0 -9][0-9][0 -9][0-9][0 -9].835 -c test.conf -e error.txt -r report.txt
Assuming there was one and only one file name matching that pattern.
Or, if you know you will always invoke the program with the same pattern, and you are able to modify the perl source code, you might build it in as a default parameter, and then you could also decide on the appropriate action in the case when more than one file name matches.
perl splitfiles.pl -i SSTEST.[0-9][0-9][0-9][0-9
Assuming there was one and only one file name matching that pattern.
Or, if you know you will always invoke the program with the same pattern, and you are able to modify the perl source code, you might build it in as a default parameter, and then you could also decide on the appropriate action in the case when more than one file name matches.
ASKER
There will never be more than one file the exact same name
After running perl splitfiles.pl -i SSTEST.[0-9][0-9][0-9][0-9 ][0-9].[0- 9][0-9][0- 9][0-9][0- 9][0-9][0- 9][0-9][0- 9].[0-9][0 -9][0-9][0 -9][0-9][0 -9][0-9][0 -9].835 -c test.conf -e error.txt -r report.txt
This is the error I get:
file] [-i <Input file>] [-e <error file>] <
sh: Input: Cannot find or open the file.
$ o <orphaned claims>] [-d <detailed report> <
sh: Syntax error: `newline or ;' is not expected.
$ y payor>] [-n 1] [-sc <allow check type sw <
sh: report: Cannot find or open the file.
$ itch>]
After running perl splitfiles.pl -i SSTEST.[0-9][0-9][0-9][0-9
This is the error I get:
file] [-i <Input file>] [-e <error file>] <
sh: Input: Cannot find or open the file.
$ o <orphaned claims>] [-d <detailed report> <
sh: Syntax error: `newline or ;' is not expected.
$ y payor>] [-n 1] [-sc <allow check type sw <
sh: report: Cannot find or open the file.
$ itch>]
The error you get seems to wrap at strange places, and also looks a lot like sh was trying to run the Usage message as a command.
Did you perchance try to put the perl command line inside of `` or $()?
And was there one and only one file name matching the pattern?
Did you perchance try to put the perl command line inside of `` or $()?
And was there one and only one file name matching the pattern?
ASKER
Did you perchance try to put the perl command line inside of `` or $()? No
And was there one and only one file name matching the pattern? No
And was there one and only one file name matching the pattern? No
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Give me an example of modify the code to do something sensible when there are more than one file names after the -i that matches the pattern or no file names after the -i.
Give me an example of a sensible thing to do.
I would have thought that generating an error would be a sensible response to erroneous input.
I would have thought that generating an error would be a sensible response to erroneous input.
ASKER
New at perl but I need my code to work when more one filename matches the file pattern.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No .txt? Your pattern is SSTEST*.txt but the example you gave has no .txt
Do you just want SSTEST*? Is there anything else that starts SSTEST that you don't want to split?