I have data in individual flat files. I'm stuck on a particular item and I've narrowed it down to how I"m assign & splitting name/values.
Sample flat file format (test.txt):
2,"1313 Mockingbird Lane"
3,"Saturday is a good day to go hiking and playing ball and a bunch of other stuff"
4,"more stuff"
Part of script that reads file:
%FIELD = (); #clears the variable
open(AUDIT, "<test.txt") or die "Cannot find file - no such file or invalid path\n";
while (<AUDIT>) {
$Line = $_;
chomp($Line);
$Line =~ s/\"$//g; #strips off ending qoute mark (")
($LineNo, $LineValue) = split(/\,\"/,$Line); #splits pair by using delimiter of comma-quote (,")
$FIELD{$LineNo} = $LineValue;
}
### CHECK Length of Various Fields to Make sure they'll print ok
if (length($FIELD{'3'}) > 50) {
print "too many characters";
}
else {
print "done";
}
close(AUDIT);
This works... however if you add a "hard return" to line #3 in the flat file so that it reads:
day to go hiking and playing ball and a bunch of other stuff"
then the script will see the $FIELD{'3'} variable as containing only "Saturday is a good" and therefore it "passes" the test.
So... it's gotta be the way I'm splitting and assigning the values (?)
Sample flat file format (test.txt):
Code:
1,"Bob Jones" 2,"1313 Mockingbird Lane"
3,"Saturday is a good day to go hiking and playing ball and a bunch of other stuff"
4,"more stuff"
Part of script that reads file:
Code:
use warnings; %FIELD = (); #clears the variable
open(AUDIT, "<test.txt") or die "Cannot find file - no such file or invalid path\n";
while (<AUDIT>) {
$Line = $_;
chomp($Line);
$Line =~ s/\"$//g; #strips off ending qoute mark (")
($LineNo, $LineValue) = split(/\,\"/,$Line); #splits pair by using delimiter of comma-quote (,")
$FIELD{$LineNo} = $LineValue;
}
### CHECK Length of Various Fields to Make sure they'll print ok
if (length($FIELD{'3'}) > 50) {
print "too many characters";
}
else {
print "done";
}
close(AUDIT);
This works... however if you add a "hard return" to line #3 in the flat file so that it reads:
Code:
3,"Saturday is a good day to go hiking and playing ball and a bunch of other stuff"
then the script will see the $FIELD{'3'} variable as containing only "Saturday is a good" and therefore it "passes" the test.
So... it's gotta be the way I'm splitting and assigning the values (?)