Dealing with EOL chars

Matt Lawrence matt.lawrence at virgin.net
Thu Jan 24 10:50:48 GMT 2008


Alex Brelsfoard wrote:
> Hi all,
>
> Sorry for making such an on-topic post, but seeing as this is my first post
> with london.pm..... I figured I might pretend to be Perl-centric.
>
> I am currently trying to work on a system that reads in all kinds of feeds.
> These feeds can be created on a PC, new/old mac, or a *nix machine.
> And I need to be able to deal with them all.
> Here's the kicker, these feeds sometimes have inline breaks, and we need to
> keep them.
>
> Does anyone have any suggestions on how to deal with this?
>
> This works:
> ---------------------------
> my $newline = "\n";
> my $file = '788_test.txt';
> open (my $file_fh, $file) || die "could not open $file for reading";
> my $file_content = <$file_fh>;
> $file_content =~ s/(?:\015{1,2}\012|\015|\012)/$newline/sg;
> foreach (split(/\n/, $file_content)) {
> print "$_\n";
> }
> close($file_fh);
> ---------------------------
>
> I can even split on that regular expression and save a line of code.
> But I'm just concerned about losing inline breaks.
>
> Thoughts?
>   

What do you mean by inline breaks?

Matt


More information about the london.pm mailing list