in reply to Can read one txt file and not another?
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Can read one txt file and not another?
by Anonymous Monk on Jul 29, 2021 at 04:56 UTC |