As ++GrandFather has already indicated, you're not showing us sufficient information to help you in any meaningful way. Have a read though "How do I post a question effectively?" and "Short, Self-Contained, Correct Example", then provide us with code we can run, as well as both inputs, both actual outputs, and both expected outputs. Wrap all data in <code>...</code> (as you did with your code above) so that we can see a verbatim copy of what you're looking at.

Copying text from a webpage is highly problematic. Sequences of whitespace (e.g. newlines, tabs, spaces) will all be compressed into a single space. I don't know how you did that but it could be part of your problem.

I suspect you may have a problem at the conceptual level (that's fine, you're at the learning stage). You're reading input line-by-line; you haven't shown any change to $/; so each line (with the possible exception of the last one) will be terminated with a newline. You can get rid of the newline at the end with chomp. There should not be any embedded newlines to split on.

"What might be the difference between the two texts?"

Consider the following series of commands (the '$' signs in the output indicate newlines):

$ cat > dog_cat_1 dog cat $ cat -vet dog_cat_1 dog$ cat$ $ cp dog_cat_1 dog_cat_2 $ cat -vet dog_cat_2 dog$ cat$ $ perl -pi -e 's/\n//g' dog_cat_2 $ cat -vet dog_cat_2 dogcat

So the difference is that you start with two distinct entities and end up with just one. See perlrun, and its -i and -p sections for more about that perl command. If you really do need to strip out newlines, doing this yourself is probably a lot less work than passing data to/from a 3rd-party website; and you stay in control of the process.

— Ken


In reply to Re: Can read one txt file and not another? by kcott
in thread Can read one txt file and not another? by Anonymous Monk

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.