jalopez453 has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I have a loop that goes through each text file. It works great, but the problem is when there is an apostrophe in my second field the script errors and does not append the detail. I am not sure what is causing this, but I was wondering if someone would be able to help me identify the issue and possibly fix it.
#!/usr/bin/perl -w use strict; use warnings; use Text::ParseWords; opendir IN, 'Outpatient'; my @in = grep { /\.txt$/ } readdir IN; # read all file names form dir +except names started with dot closedir IN; for my $in (@in) { open IN, '<', "Outpatient/$in" || next; open OUT, '>', "TXT/$in" || die "can't open file Formatted/$in"; while(<IN>) { my @f = quotewords ',', 0, $_; print OUT join "," => @f; } close OUT; close IN; } INPUT FILE: """555522""",MEN'S HEALTH DEPARTMENT,"""12/31""" OUTPUT FILE: **BLANKS EXPECTED OUTPUT: 555522,MEN'S HEALTH DEPARTMENT,12/31
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Issue with Loop when Apostrophe in Field
by pryrt (Abbot) on Oct 01, 2020 at 18:53 UTC | |
|
Re: Issue with Loop when Apostrophe in Field
by jwkrahn (Abbot) on Oct 01, 2020 at 20:02 UTC | |
|
Re: Issue with Loop when Apostrophe in Field
by perlfan (Parson) on Oct 01, 2020 at 18:48 UTC |