Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: List comparison problem

by hippo (Bishop)
on Aug 16, 2019 at 09:34 UTC ( [id://11104560]=note: print w/replies, xml ) Need Help??


in reply to Re^2: List comparison problem
in thread List comparison problem

the first line isn't useful, because the second code line will remove all trailing white spaces, including the \r Windows CR character.

While I take your point, they are not entirely equivalent. The difference is that the first line removes all the \r characters wherever they appear in the line. The second does not do that.

use strict; use warnings; use Test::More tests => 2; my $have = "foo\rbar\rbaz\r\n"; my $want = "foobarbaz"; $have =~ s/\s+$//; isnt $have, $want, 'Not all carriage returns removed'; $have =~ s/\r//g; is $have, $want, 'All carriage returns removed';

I've spent far too much time over the years fighting poorly-formed, non-compliant, randomly-encoded data originating from Windows to assume anything about the quality of such data. YMMV.

Replies are listed 'Best First'.
Re^4: List comparison problem
by Laurent_R (Canon) on Aug 16, 2019 at 21:14 UTC
    Yes, you're absolutely right, they are not entirely equivalent. ++

    But the aim of the OP code is really obviously to remove Windows CR characters from Windows line endings. And for that, that's OK.

    Having said that, I completely agree that I have also seen quite a few times poorly-formed, non-compliant, randomly-encoded data originating from Windows.

    I should also say that if my input was similar to your $have variable, I would probably have to think twice before I decided to remove CR characters within the string. It would really depend on that the final aim of the file comparison is.

Re^4: List comparison problem
by perlmonkster (Initiate) on Aug 17, 2019 at 00:52 UTC
    THANKS to all of you for the information. -perlmonkster

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104560]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found