Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Same code different result in WIN and MAC, help please

by JHG (Initiate)
on Mar 11, 2012 at 17:25 UTC ( [id://958982]=perlquestion: print w/replies, xml ) Need Help??

JHG has asked for the wisdom of the Perl Monks concerning the following question:

I wrote this in WIN to read a multiline .txt file line by line

<code while((INFILE)) {print $_;} >

Which is straightforward and NOT in @List context!

In WIN it worked perfectly for years, when I copy&paste a word.doc or .docx text into a simple txt file to use as INFILE. But when I do the same in MAC, that is copying a word.docx text to paste in a simple txt file, the above code churns out a single line whatever the lenght of the original text! I added a linecount in both system: in WIN it counts the lines correctly wether in MAC the result is always 1 line only.

I would very much appreciate a solution to this problem, since I have hundreds of texts to churn with my routine that wraps HTML tag around each line.

  • Comment on Same code different result in WIN and MAC, help please

Replies are listed 'Best First'.
Re: Same code different result in WIN and MAC, help please
by toolic (Bishop) on Mar 11, 2012 at 17:30 UTC
    I don't hava a Mac, but maybe Newlines will help.
Re: Same code different result in WIN and MAC, help please
by bitingduck (Chaplain) on Mar 11, 2012 at 18:05 UTC

    I do nearly all my Perl on a Mac and it recognizes the EOLs just fine, and then runs fine when I deploy it on a FreeBSD system.

    Are you using the same input data? Your file on the mac might not have any line breaks. Try looking at the source data with a text editor, and maybe post samples of the data files. It's probably some pathology of your data.

    Edit:I think your source file has no line breaks. I just grabbed a random .docx out of my files and cut and pasted from word into bbedit. Each paragraph is one line, and the only line breaks are at the end of paragraphs. Word files (and I think most word processors) have always been this way. When you paste it into something on Windows, the editor probably inserts breaks. when you paste it into something on the Mac, it probably doesn't. Try using "save as" and (edit:then select "text") then check the box that says "insert line breaks". Or since you know the length of the lines (or can pick whatever you want it to be) just insert your own as needed.

Re: Same code different result in WIN and MAC, help please
by tangent (Parson) on Mar 11, 2012 at 17:59 UTC
    This suggests that PERL does not recognize MAC EndOfLine which looks very strange to me.
    Which system were the text files created on? Maybe you meant to say that your script running on the MAC does not recognise WIN EndOfLine?
Re: Same code different result in WIN and MAC, help please
by ikegami (Patriarch) on Mar 12, 2012 at 19:04 UTC

    On Windows, text files should look like:

    line1 CR LF line2 CR LF line3 CR LF

    Where CR stands for Carriage Return (0D) and LF stands for Line Feed (0A).

    The unix format is also acceptable on Windows:

    line1 LF line2 LF line3 LF

    On Macs, you need to use the unix format:

    line1 LF line2 LF line3 LF

    But for some reason, your text file is using the format ancient Macs (pre OS-X) used:

    line1 CR line2 CR line3 CR

    That's wrong. <> reads until the first LF (by default), so it perceives the whole file to be one line. Then, when you print it, the terminal causes each line to be written on top of the previous because CR causes the cursor to be moved to the first column of the line.

    print "aaaaa\rbbbb\rccc\n"; # Prints cccba

    Fix your corrupted file.

Log In?
Username:
Password:

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

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

    No recent polls found