Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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'

Replies are listed 'Best First'.
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:


      ... 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985157]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2018-05-28 10:15 GMT
Find Nodes?
    Voting Booth?