Marshall has asked for the wisdom of the Perl Monks concerning the following question:
I am running on Win 10, Active State Perl (v5.24.3). Above code will work with <LF> (Unix) or <CR><LF> (Windows) line endings but evidently not with <CR> line endings. My user has changed his workflow to only make <CR><LF> files and so things are fine moving forward. However, I am curious. I remember previous versions of Perl working fine when reading <CR> terminated lines. Any ideas?open my $in, '<', "file" or die "$!"; #open worked while (my $line = <$in>){print $line;} #just a few characters print
Update fixed file handle typing mistake. More of actual code shown later in thread.
Update: Thanks for the interesting input, especially from LanX and haukex. Fortunately I don't have to solve the general problem at the moment (read text file with unknown line endings). When I wrote the code, I implemented it in such a way that Unix or Windows endings work fine for input and all files that I generate have pure line endings of the platform the code was run on. This <CR> file was a "weird duck". I spent some more time talking with my user and found out that he generated the <CR> file on a Windows platform. But had his text editor set to use <CR> line endings instead of Windows standard <CR><LF>! We agreed that this is "outside of spec" and "don't do that". Since the user symptom was "program didn't do anything" (no valid input records read), I've added a simple print of number of records processed. Program will exit with non-zero error code if that number is zero just in case this utility is ever used in a batch file. So things are fine now and I incrementally learned a bit.
|
|---|