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

Re: Problem with files read to array split on empty lines

by tobyink (Abbot)
on Aug 03, 2012 at 05:59 UTC ( #985157=note: print w/ replies, xml ) Need Help??


in reply to Problem with files read to array split on empty lines

Are you sure the files are identical? Look at their file sizes. Do they perhaps have different line endings? \n versus \r\n.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: Problem with files read to array split on empty lines
Select or Download Code
Re^2: Problem with files read to array split on empty lines
by jhoop (Acolyte) on Aug 03, 2012 at 06:05 UTC

    I believe so but I can't say for sure. The copies on server are the originals, I pulled them to the home machine to test them after the script didn't work as expected. Windows does claim two of them are slightly less (-.01k) in size.

      How did you transfer them? FTP? Many FTP clients will choose to transfer some files (often using the file name as a hint as to whether it's appropriate) in "ASCII mode" which means that it will change the line to the standard line endings for the local system during transfer.

      Try replacing your /\n{2,}/ regular expression with:

      /(?:\r?\n|\r){2,}/

      ... which should match two or more occurrences of any common line ending.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        Tobyink, thank you. The files were downloaded through the server's cPanel web UI. After your initial reply i made a attempt at such a regex but my eyes were starting to glass over. I will try your suggestion and report back, although currently the server appears to be down :/ I would have thought that changing $/ to the empty string would have caught all instances of an empty line (as has been suggested in other nodes) but clearly I'm missing something.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-09-16 04:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls