I tried to output the chomped text to a txt file. When I open that text file in a text editor it shows weird overlapping text (like some sort of graphical problem).   [from this; emphasis added]

afoken has already covered the cross-system line-end mismatch and chomp problems pretty well. Here's a further example:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "dd $/; ;; my $s = qq{abc\r\n}; chomp $s; dd $s; ;; my @lines = (qq{Overlapping\r\n}, qq{Strange\r\n}, qq{Text\r\n}); dd \@lines; ;; chomp @lines; dd \@lines; ;; my $line = join '', @lines; dd $line; ;; print qq{$line}; " "\n" "abc\r" ["Overlapping\r\n", "Strange\r\n", "Text\r\n"] ["Overlapping\r", "Strange\r", "Text\r"] "Overlapping\rStrange\rText\r" Textngeping

The other thing that occurs to me is that your original file has "invisible" whitespace characters other than the  \r \n line-enders: spaces, tabs, etc. If these exist at the end of a line, it will cause a problem. Try something like (untested):
    open my $filehandle, '<', ... or die "...: $!";
    ...
    my $content = do { local $/;  <$filehandle>; };
    $content =~ tr{\x20\t\f\r\n}{}d;

In general, processing a file of a few hundred megabytes entirely held in memory should not be a big problem, depending on what you're doing, and you're basic approach (insofar as I can understand what it is) looks ok to me.

And, of course, the golden rule: Know Your Data!

Update: BTW:  my $content = do { local $/;  <$filehandle>; }; is the "file slurp" idiom; it does a raw read of the entire file to a string.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Regular expressions across multiple lines by AnomalousMonk
in thread Regular expressions across multiple lines by abcd

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.