I accidently placed this as a reply to another post and in the C forum.
I have a function which parses a CSV file then extracts records from that file and writes those records to another file. I pass references to the file handles to this function( a reference to $INFILE and $OUTFILE). When the function attempts to parse the CSV file I get the following parse error message: parse failed: No such file or directory. I am able to parse 2 other CSV files but this one particular generates this error message. Does anyone have any ideas on what could cause this parse error? Thanks
in advance for any help offered.
Here's the code:
In the main section:
my $INFILE = "/temp/info.txt";
my $OUTFILE = "/temp/master.txt";
open(IFILE, "$INFILE" || die "Can\'t open input file\n";
open(OFILE, "$OUTFILE" || die "Can\'t open output file\n";
# pass file handle references to function
writeToMasterFile(\*IFILE, \*OFILE);
# function
sub writeToMasterFile
{
my ($f1, $f2) = @_;
if ( -r $f1 )
{
print "File: $f1 exists and is readable\n";
}
else
{
print "File: $f1 does not exist and/or is not readable\n";
}
while (<$f1>)
{
chomp;
my $csv2 = Text::CSV_XS->new;
print "$_\n";
if ( $csv2->parse($_))
{
my @mail_entry = $csv2->fields;
my($accttype, $fname, $mname, $lname, $email, $pphone, $bphone, $address, $city, $state, $pcode, $province, $country, $comments, $refcocust, $refcoacct, $branch, $date, $time) = @mail_entry;
#print "\$date = $date\n\n";
#print "\$time = $time\n\n";
($hr, $min, $sec) = split /:/, $time;
($mon, $day, $yr) = split /-/, $date;
#print "\$hr = ", $hr, "\n";
#print "\$min = ", $min, "\n";
#print "\$sec = ", $sec, "\n\n";
#print "\$mon = ", $mon, "\n";
#print "\$day = ", $day, "\n";
#print "\$yr = ", $yr, "\n\n";
if ( $mon == $ymon && $day == $yday && $yr == $yyr )
{
if ( $hr >= 12 )
{
print $f2 $_, "\n";
}
elsif ( $mon == $tmon && $day == $tday && $yr == $tyr )
{
if ( $hr < 12 )
{
print $f2 $_, "\n";
}
}
}
}
else
{
bail("parse() failed: $!\n"
}
}
}
I have a function which parses a CSV file then extracts records from that file and writes those records to another file. I pass references to the file handles to this function( a reference to $INFILE and $OUTFILE). When the function attempts to parse the CSV file I get the following parse error message: parse failed: No such file or directory. I am able to parse 2 other CSV files but this one particular generates this error message. Does anyone have any ideas on what could cause this parse error? Thanks
in advance for any help offered.
Here's the code:
In the main section:
my $INFILE = "/temp/info.txt";
my $OUTFILE = "/temp/master.txt";
open(IFILE, "$INFILE" || die "Can\'t open input file\n";
open(OFILE, "$OUTFILE" || die "Can\'t open output file\n";
# pass file handle references to function
writeToMasterFile(\*IFILE, \*OFILE);
# function
sub writeToMasterFile
{
my ($f1, $f2) = @_;
if ( -r $f1 )
{
print "File: $f1 exists and is readable\n";
}
else
{
print "File: $f1 does not exist and/or is not readable\n";
}
while (<$f1>)
{
chomp;
my $csv2 = Text::CSV_XS->new;
print "$_\n";
if ( $csv2->parse($_))
{
my @mail_entry = $csv2->fields;
my($accttype, $fname, $mname, $lname, $email, $pphone, $bphone, $address, $city, $state, $pcode, $province, $country, $comments, $refcocust, $refcoacct, $branch, $date, $time) = @mail_entry;
#print "\$date = $date\n\n";
#print "\$time = $time\n\n";
($hr, $min, $sec) = split /:/, $time;
($mon, $day, $yr) = split /-/, $date;
#print "\$hr = ", $hr, "\n";
#print "\$min = ", $min, "\n";
#print "\$sec = ", $sec, "\n\n";
#print "\$mon = ", $mon, "\n";
#print "\$day = ", $day, "\n";
#print "\$yr = ", $yr, "\n\n";
if ( $mon == $ymon && $day == $yday && $yr == $yyr )
{
if ( $hr >= 12 )
{
print $f2 $_, "\n";
}
elsif ( $mon == $tmon && $day == $tday && $yr == $tyr )
{
if ( $hr < 12 )
{
print $f2 $_, "\n";
}
}
}
}
else
{
bail("parse() failed: $!\n"
}
}
}