jhoop has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with files read to array split on empty lines
by tobyink (Canon) on Aug 03, 2012 at 05:59 UTC | |
by jhoop (Acolyte) on Aug 03, 2012 at 06:05 UTC | |
by tobyink (Canon) on Aug 03, 2012 at 06:37 UTC | |
by jhoop (Acolyte) on Aug 03, 2012 at 19:12 UTC | |
|
Re: Problem with files read to array split on empty lines
by davido (Cardinal) on Aug 03, 2012 at 07:39 UTC | |
by jhoop (Acolyte) on Aug 03, 2012 at 19:19 UTC | |
|
Re: Problem with files read to array split on empty lines
by frozenwithjoy (Priest) on Aug 03, 2012 at 05:45 UTC | |
by jhoop (Acolyte) on Aug 03, 2012 at 05:51 UTC |