Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   funny characters in Date::Pcalc (http://www.velocityreviews.com/forums/t897895-funny-characters-in-date-pcalc.html)

cartercc@gmail.com 05-10-2006 12:24 PM

funny characters in Date::Pcalc
 
Installed Steffen Beyer's Date::Pcalc from CPAN.

Wrote a little test program to see if it works and ran WITH WARNINGS:

1 #!/usr/bin/perl
2 use strict;
3 use Date::Pcalc;
4
5 my ($doy,$year,$month,$date,$day);
6
7 print "Enter year:\n";
8 $year = <STDIN>;
9 chomp $year;
10 print "The year is $year.\n";
11
12 exit();

Test program worked but I got much more than I bargained for. I know
what's going on but have no idea how to fix it. Ideas?

Here's a SAMPLE of the output-----------------------------
Malformed UTF-8 character (unexpected non-continuation byte 0x6f,
immediately after start byte 0xe7) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 158.
Malformed UTF-8 character (unexpected non-continuation byte 0x72,
immediately after start byte 0xe9) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 191.
Malformed UTF-8 character (unexpected non-continuation byte 0x62,
immediately after start byte 0xe1) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 192.
Malformed UTF-8 character (unexpected non-continuation byte 0x61,
immediately after start byte 0xe7) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 195.
Malformed UTF-8 character (unexpected non-continuation byte 0x62,
immediately after start byte 0xe1) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 196.
Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 203.
Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 203.
Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 203.
Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 204.
Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 204.
Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
line 229.
Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
line 229.
Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
line 229.
Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
line 229.
Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
line 229.
Malformed UTF-8 character (unexpected non-continuation byte 0x62,
immediately after start byte 0xe1) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 229.
Malformed UTF-8 character (unexpected non-continuation byte 0x61,
immediately after start byte 0xe7) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 254.
Malformed UTF-8 character (unexpected non-continuation byte 0x6f,
immediately after start byte 0xf1) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 254.
Malformed UTF-8 character (unexpected non-continuation byte 0x73,
immediately after start byte 0xea) at
/usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 255.
Enter year:
2006
The year is 2006.
[cal@serdev cal]$


Dave 05-10-2006 12:58 PM

Re: funny characters in Date::Pcalc
 

<cartercc@gmail.com> wrote in message
news:1147263866.915845.323530@y43g2000cwc.googlegr oups.com...
> Installed Steffen Beyer's Date::Pcalc from CPAN.
>
> Wrote a little test program to see if it works and ran WITH WARNINGS:
>
> 1 #!/usr/bin/perl
> 2 use strict;
> 3 use Date::Pcalc;
> 4
> 5 my ($doy,$year,$month,$date,$day);
> 6
> 7 print "Enter year:\n";
> 8 $year = <STDIN>;
> 9 chomp $year;
> 10 print "The year is $year.\n";
> 11
> 12 exit();
>
> Test program worked but I got much more than I bargained for. I know
> what's going on but have no idea how to fix it. Ideas?
>
> Here's a SAMPLE of the output-----------------------------
> Malformed UTF-8 character (unexpected non-continuation byte 0x6f,
> immediately after start byte 0xe7) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 158.
> Malformed UTF-8 character (unexpected non-continuation byte 0x72,
> immediately after start byte 0xe9) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 191.
> Malformed UTF-8 character (unexpected non-continuation byte 0x62,
> immediately after start byte 0xe1) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 192.
> Malformed UTF-8 character (unexpected non-continuation byte 0x61,
> immediately after start byte 0xe7) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 195.
> Malformed UTF-8 character (unexpected non-continuation byte 0x62,
> immediately after start byte 0xe1) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 196.
> Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 203.
> Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 203.
> Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 203.
> Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 204.
> Malformed UTF-8 character (1 byte, need 3, after start byte 0xec) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 204.
> Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
> preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
> line 229.
> Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
> preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
> line 229.
> Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
> preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
> line 229.
> Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
> preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
> line 229.
> Malformed UTF-8 character (unexpected continuation byte 0xaa, with no
> preceding start byte) at /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm
> line 229.
> Malformed UTF-8 character (unexpected non-continuation byte 0x62,
> immediately after start byte 0xe1) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 229.
> Malformed UTF-8 character (unexpected non-continuation byte 0x61,
> immediately after start byte 0xe7) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 254.
> Malformed UTF-8 character (unexpected non-continuation byte 0x6f,
> immediately after start byte 0xf1) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 254.
> Malformed UTF-8 character (unexpected non-continuation byte 0x73,
> immediately after start byte 0xea) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 255.
> Enter year:
> 2006
> The year is 2006.
> [cal@serdev cal]$
>


The source file is in ISO-8859-1 encoding, but the perl interpreter seems to
be assuming that it is utf-8, so every time it reaches an accented character
it complains. Try converting the source file to utf-8. (I found that pasting
the source into VIM on Windows XP and saving it produced the conversion).

Dave



David Squire 05-10-2006 01:02 PM

Re: funny characters in Date::Pcalc
 
cartercc@gmail.com wrote:
> Installed Steffen Beyer's Date::Pcalc from CPAN.
>
> Wrote a little test program to see if it works and ran WITH WARNINGS:
>
> 1 #!/usr/bin/perl
> 2 use strict;


I do not see "use warnings;" here, despite what you say above.

> 3 use Date::Pcalc;
> 4
> 5 my ($doy,$year,$month,$date,$day);
> 6
> 7 print "Enter year:\n";
> 8 $year = <STDIN>;
> 9 chomp $year;
> 10 print "The year is $year.\n";
> 11
> 12 exit();
>
> Test program worked but I got much more than I bargained for. I know
> what's going on but have no idea how to fix it. Ideas?
>
> Here's a SAMPLE of the output-----------------------------
> Malformed UTF-8 character (unexpected non-continuation byte 0x6f,
> immediately after start byte 0xe7) at
> /usr/lib/perl5/site_perl/5.8.0/Date/Pcalc.pm line 158.


[snip]

Did you type your year in a terminal? If so, is your terminal providing
ASCII or UTF8 as input format? Many recent linuces provide UTF-8, and I
would guess that perhaps your perl (or Date::Pcalc) is not expecting that.

I just downloaded the package from CPAN and tested your script, getting:

>./test.pl

Enter year:
1986
The year is 1986.

What happens if you add "binmode STDIN;" before your line 8?

DS

David Squire 05-10-2006 01:13 PM

Re: funny characters in Date::Pcalc
 
David Squire wrote:

> Did you type your year in a terminal? If so, is your terminal providing
> ASCII or UTF8 as input format? Many recent linuces provide UTF-8, and I
> would guess that perhaps your perl (or Date::Pcalc) is not expecting that.


Or indeed vice-versa.

DS

Dave 05-10-2006 01:31 PM

Re: funny characters in Date::Pcalc
 

"David Squire" <David.Squire@no.spam.from.here.au> wrote in message
news:e3souj$g49$1@news.ox.ac.uk...
> David Squire wrote:
>
>> Did you type your year in a terminal? If so, is your terminal providing
>> ASCII or UTF8 as input format? Many recent linuces provide UTF-8, and I
>> would guess that perhaps your perl (or Date::Pcalc) is not expecting
>> that.

>
> Or indeed vice-versa.
>
> DS


This is not relevant as utf-8 is a effectively superset of ascii and simple
numbers are the same in both. The warnings are being produced by the line:
use Date::PCalc;

The issue is with a conflict between the encoding of the source file for
Date::PCalc and what Perl is expecting (which may be influenced by
enviroment variables on the OP's machine).

Dave




cartercc@gmail.com 05-10-2006 02:17 PM

Re: funny characters in Date::Pcalc
 
> I do not see "use warnings;" here, despite what you say above.

$perl -w caltest.plx

CC


cartercc@gmail.com 05-10-2006 02:32 PM

Re: funny characters in Date::Pcalc
 
Since I needed Date::Pcalc to work, I edited the pm to remove (or
comment out) all the funny characters, so I'm a happy camper. And since
I use English only, the funny characters are not an issue.

This is like solving a chess problem by upsetting the board -- but it
worked.

Thanks, CC.


Peter J. Holzer 05-10-2006 06:37 PM

Re: funny characters in Date::Pcalc
 
Dave wrote:
> <cartercc@gmail.com> wrote in message
> news:1147263866.915845.323530@y43g2000cwc.googlegr oups.com...
>> Installed Steffen Beyer's Date::Pcalc from CPAN.
>>
>> Wrote a little test program to see if it works and ran WITH WARNINGS:
>>
>> 1 #!/usr/bin/perl
>> 2 use strict;
>> 3 use Date::Pcalc;

[...]
>> Here's a SAMPLE of the output-----------------------------
>> Malformed UTF-8 character (unexpected non-continuation byte 0x6f,
>> immediately after start byte 0xe7) at

[...]
>
> The source file is in ISO-8859-1 encoding, but the perl interpreter
> seems to be assuming that it is utf-8, so every time it reaches an
> accented character it complains. Try converting the source file to
> utf-8.


If you do, you should probably also add

use utf8;

near the top. Or alternatively, you can leave it in ISO-8859-1 encoding
and add

use encoding 'iso-8859-1';

instead. You may also want to send a bug report to the author.

> (I found that pasting the source into VIM on Windows XP and
> saving it produced the conversion).


Or just open the file with vim (vim usually guesses the charset right),
then :set fileencoding=utf-8 and save the file again.

hp

--
_ | Peter J. Holzer | Man könnte sich [die Diskussion] auch
|_|_) | Sysadmin WSR/LUGA | sparen, wenn man sie sich einfach sparen
| | | hjp@hjp.at | würde.
__/ | http://www.hjp.at/ | -- Ralph Angenendt in dang 2006-04-15


All times are GMT. The time now is 08:48 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.