<div dir="ltr">The short answer is that you are working with UTF-8 formatted files and the first record in your file contains 3 extra bytes (called the Byte Order Mark or BOM) to mark the file as Unicode. However, you are not telling Perl to treat them as UTF-8 files. You need to either:<div><ol><li>Save your files in ASCII (which will probably break hospitals.csv since one of the hospital names contains a Unicode character).</li><li>Tell Perl to read the files as UTF-8.</li></ol><div>To do #2, you just can change the file open lines to:</div><div><br></div><div>open (HOSPITALS, '<:utf8', "hospitals.csv") or die $!;</div><div>...</div><div>open (PATIENTS, '<:utf8', "september.csv") or die $!;</div><div><br></div><div>Another option is to use <a href="https://metacpan.org/pod/File::BOM">File::BOM</a> to add BOM detection to your script.</div><div><br></div><div>As a positive side-effect to the change suggested above, the 3-argument version of open is safer than the 2-arg version if you ever decide to use a variable name in your filenames (e.g., "$month.csv").</div><br><div>Perl has excellent Unicode support (better than most), but, for whatever reason, it does not have built-in BOM detection for input files. (It does detect BOM for script files it will be executing, just not for regular input files.)</div></div><div><br></div><div>Cheers.</div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 13, 2015 at 11:33 AM Simons, Tony <<a href="mailto:ts-pm@tvortex.net" target="_blank">ts-pm@tvortex.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Please excuse the test message in reply to Paul's Message.  I did some printf's in the code to test the output.  The result Paul is seeing is only on the first record and it's happening in the first occurance of:</div><div><br></div><div>my $firstDir = substr ($patientId...</div><div><br></div><div>if I print the values of $patientId and $hospitalId before the substr the data appears to be correct.</div><div><br></div><div>I also tried something since the data is numeric in nature.  I tried:</div><div>my $patientId = int $ids[0];</div><div><br></div><div> which resulted in the following as an error since it's not text.</div><div><br></div><div>M-oM-;M-?514027<br></div><div><br></div><div>So it appears to be something that's happening with the substr and the data in the file.  I see no special characters in the file itself using vi :set list  I also did a dos2unix on the file to make sure it's using the right format.   I have read that there are problems with perl and files in UTF-8 format.  Is that a potential problem?</div></div>
_______________________________________________<br>
Omaha-pm mailing list<br>
<a href="mailto:Omaha-pm@pm.org" target="_blank">Omaha-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/omaha-pm" rel="noreferrer" target="_blank">http://mail.pm.org/mailman/listinfo/omaha-pm</a></blockquote></div></div></div><div dir="ltr">-- <br></div><div dir="ltr">Sterling Hanenkamp<div><a href="http://sterling.hanenkamp.com/stfl/">http://sterling.hanenkamp.com/stfl/</a></div><div>785-370-4454</div></div>