I am puzzled. I have a script that should split a bunch of input files' contents by empty lines, however the same script that works in my local machine doesn't work on the same files when executed from the server install I want to run it from. The code below splits every file into 2 parts when run from the server - the split occurring only at the first break of multiple text blocks separated by blank lines.. When run from my local install it operates properly. I'm new to running scripts from a remote install, but I can't figure out what the issue is.. Any help much appreciated!

my @mailfiles = </path/to/files/*>; foreach my $file (@mailfiles){ my @text_blocks; open TEXT, '<', $file or die "could not open $file"; my $text; while (<TEXT>){ $text .= $_; } @text_blocks = split(/\n{2,}/, $text); close TEXT; #also tried the method below with similar results #{ # local $/ = ''; # @text_blocks = <TEXT>; #} #close TEXT; print scalar(@text_blocks); }

prints '2222' when run on the server, '4426' at home when run on the same four files.

edit: I should have mentioned that the break between the first and second text block (the only point where the server script splits properly) is the break between the header and body of an email message read to the file by mail::imapclient. The rest of the blank lines are inside the body of the original email message.


In reply to Problem with files read to array split on empty lines by jhoop

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.