Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Reading text file with <CR> line endings

by Marshall (Canon)
on Mar 05, 2018 at 18:45 UTC ( [id://1210373]=note: print w/replies, xml ) Need Help??


in reply to Re: Reading text file with <CR> line endings
in thread Reading text file with <CR> line endings

Yes, that approach would work. When I considered that idea, I was thinking of opening the file in bin mode. Read a block of data. Use substr index to find first <CR> and then run substr index to find first <LF>, from those index numbers I could figure out what kind of file it was. I'd probably close file and report back the line ending value from a "discover_line_ending sub". And have main program re-open the file in text mode with correct input line separator. BTW, substrindex is a very fast critter because it is "stupid" - searching to the end of the input block with no search value found is "fast".

Another idea I considered was to slurp in the whole file as binary - the max size of this file is small enough to do that. Then use split to do my own line division. The input line separator cannot be a regex, but split can use a regex.

As I mention in my now updated question post, I found out where this "weird duck" file came from. There is no need for me to solve this tricky problem at this time. Users do the darndest things! The "hey, don't do that!" answer appears to meet all of my requirements and user is fine with that "solution". Not every complicated problem requires an actual implementation. At some point in the future, I may have to actually implement a solution for this problem and what I've learned in this thread will be helpful. I think there are also fine points in this thread that could be useful for other problems. In my opinion, you can never "know too much" about Perl.

  • Comment on Re^2: Reading text file with <CR> line endings

Replies are listed 'Best First'.
Re^3: Reading text file with <CR> line endings
by hippo (Bishop) on Mar 06, 2018 at 09:23 UTC

    substr doesn't search at all. I suppose you meant index?

      Yes index is the right function - corrected above.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found