This is a much simplified version of a script that I'm using. The program finds the number 1 in brackets-((1))-and replaces it with a sentence. The text is French because the program translates into French and I want to know it works properly with accents.
replace.sh (can just be pasted into shell):
The result is:
In an editor it displays as:
In shell it displays as:
The file was a UTF-8 before perl wrote on it and now it is iso-8859-1:
I would like the result to be:
It seems that after using echo the file format changes.
Hi, I'm using putty and when I try to write ü it writes | (or when I try to write é , it writes i)
I tried to change settings/translation of putty but with no success
I have KSH
# locale
LANG=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"... (3 Replies)
Hi,
Can someone please clarify how we are able to use both IO and GLOB symbols of a package variable interchangeably?
Please consider the following code:
open(FH,"myfile") || die "Unable to open file myfile:$@";
my $glob_var = *main::FH{GLOB};
my $io_var = *main::FH{IO};
print $glob_var... (0 Replies)
hi folks ,
I have a shell script which contain SQL query that dump some data from the DB in arabic and this data is written to a file in unix machine but the problem that the arabic data is appear like ??????????|111|???????? even when I move it to my windows XP machine.
Any one have an Idea... (2 Replies)
Hello All
I have a set of files, each one containing some lines that follows that regex:
regex='disabled\,.*\,\".*\"'and here is what file says about each files:
file <random file>
<random file> ASCII text, with CRLF line terminatorsSo, as an example, here is what a file ("Daffy Duck - The... (3 Replies)
I have oracle 9i database installed with UTF-8 Encoding.
I want a perl script that converts unicode to utf8 before commiting in database and utf8 to unicode when retreiving from database
For example :
the word Ïntêrnatïônàlîzâtion has to be stored in database as Internationalization and when retreived... (6 Replies)
Hi,
How do I print a line with symbols in a file?
Exp:
If I want to print line: Hi "Lisa;John"
Command:
print FILE "Hi "Lisa;John""; - will give me error Bareword found where operator expected...
Can someone advise how can I print any line consiting symbols like example above. Thanks... (3 Replies)
Hi,
I am beginner to Unix.
My requirement is to validate the encoding used in the incoming file(csv,txt).If it is encoded with UTF-8 format,then the file should remain as such otherwise i need to chnage the encoding to UTF-8.
Please advice me how to proceed on this. (7 Replies)
I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell... (5 Replies)
Hi all!!
I´m using command file -i myfile.xml to validate XML file encoding, but it is just saying regular file . I´m expecting / looking an output as UTF8 or ANSI / ASCII
Is there command to display the files encoding?
Thank you! (2 Replies)
Discussion started by: mrreds
2 Replies
LEARN ABOUT OSX
encoding::warnings
encoding::warnings(3pm) Perl Programmers Reference Guide encoding::warnings(3pm)NAME
encoding::warnings - Warn on implicit encoding conversions
VERSION
This document describes version 0.11 of encoding::warnings, released June 5, 2007.
SYNOPSIS
use encoding::warnings; # or 'FATAL' to raise fatal exceptions
utf8::encode($a = chr(20000)); # a byte-string (raw bytes)
$b = chr(20000); # a unicode-string (wide characters)
# "Bytes implicitly upgraded into wide characters as iso-8859-1"
$c = $a . $b;
DESCRIPTION
Overview of the problem
By default, there is a fundamental asymmetry in Perl's unicode model: implicit upgrading from byte-strings to unicode-strings assumes that
they were encoded in ISO 8859-1 (Latin-1), but unicode-strings are downgraded with UTF-8 encoding. This happens because the first 256
codepoints in Unicode happens to agree with Latin-1.
However, this silent upgrading can easily cause problems, if you happen to mix unicode strings with non-Latin1 data -- i.e. byte-strings
encoded in UTF-8 or other encodings. The error will not manifest until the combined string is written to output, at which time it would be
impossible to see where did the silent upgrading occur.
Detecting the problem
This module simplifies the process of diagnosing such problems. Just put this line on top of your main program:
use encoding::warnings;
Afterwards, implicit upgrading of high-bit bytes will raise a warning. Ex.: "Bytes implicitly upgraded into wide characters as iso-8859-1
at - line 7".
However, strings composed purely of ASCII code points (0x00..0x7F) will not trigger this warning.
You can also make the warnings fatal by importing this module as:
use encoding::warnings 'FATAL';
Solving the problem
Most of the time, this warning occurs when a byte-string is concatenated with a unicode-string. There are a number of ways to solve it:
o Upgrade both sides to unicode-strings
If your program does not need compatibility for Perl 5.6 and earlier, the recommended approach is to apply appropriate IO disciplines,
so all data in your program become unicode-strings. See encoding, open and "binmode" in perlfunc for how.
o Downgrade both sides to byte-strings
The other way works too, especially if you are sure that all your data are under the same encoding, or if compatibility with older
versions of Perl is desired.
You may downgrade strings with "Encode::encode" and "utf8::encode". See Encode and utf8 for details.
o Specify the encoding for implicit byte-string upgrading
If you are confident that all byte-strings will be in a specific encoding like UTF-8, and need not support older versions of Perl, use
the "encoding" pragma:
use encoding 'utf8';
Similarly, this will silence warnings from this module, and preserve the default behaviour:
use encoding 'iso-8859-1';
However, note that "use encoding" actually had three distinct effects:
o PerlIO layers for STDIN and STDOUT
This is similar to what open pragma does.
o Literal conversions
This turns all literal string in your program into unicode-strings (equivalent to a "use utf8"), by decoding them using the
specified encoding.
o Implicit upgrading for byte-strings
This will silence warnings from this module, as shown above.
Because literal conversions also work on empty strings, it may surprise some people:
use encoding 'big5';
my $byte_string = pack("C*", 0xA4, 0x40);
print length $a; # 2 here.
$a .= ""; # concatenating with a unicode string...
print length $a; # 1 here!
In other words, do not "use encoding" unless you are certain that the program will not deal with any raw, 8-bit binary data at all.
However, the "Filter => 1" flavor of "use encoding" will not affect implicit upgrading for byte-strings, and is thus incapable of
silencing warnings from this module. See encoding for more details.
CAVEATS
For Perl 5.9.4 or later, this module's effect is lexical.
For Perl versions prior to 5.9.4, this module affects the whole script, instead of inside its lexical block.
SEE ALSO
perlunicode, perluniintro
open, utf8, encoding, Encode
AUTHORS
Audrey Tang
COPYRIGHT
Copyright 2004, 2005, 2006, 2007 by Audrey Tang <cpan@audreyt.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>
perl v5.16.2 2012-08-26 encoding::warnings(3pm)