Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: convert files to ansi (8859-1)

by Corion (Patriarch)
on Mar 29, 2017 at 08:17 UTC ( [id://1186331]=note: print w/replies, xml ) Need Help??


in reply to Re^2: convert files to ansi (8859-1)
in thread convert files to ansi (8859-1)

You cannot read octets from a file and then hope that Perl will know that you meant UTF-8. You always have to decode your input and encode your output.

Replies are listed 'Best First'.
Re^4: convert files to ansi (8859-1)
by Yaerox (Scribe) on Mar 29, 2017 at 08:33 UTC
    Maybe we talk past each other?

    My utf8 to iso-8859-1 should do the following:
    - read file into scalar
    - eval decode utf8
    -- if we get an error, then i simply say it's iso-8859-1 and I don't do anything
    -- it we get no error, then i use the decoded string

    On the other script iso-8859-1 to utf8, I wanna go the same way:
    - read file into scalar
    - eval decode iso-8859-1
    -- if we get an error, then i simply say it's utf8 and I don't do anything
    -- it we get no error, then i use the decoded string

    Now I expect we get an eval decode iso-8859-1 error if the input file is utf8, but I don't.
      -- if we get an error, then i simply say it's utf8 and I don't do anything

      That's wrong.

      If your input is bytes that are a valid UTF-8 sequence, you still need to call decode on it to have usable strings in Perl.

        Okay. So perl works internal using single-byte code?

        But why does eval decode iso-8859-1 don't throw an error if the input file is utf8?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found