Encode::decode() clears scalar being decoded?

R

Robert Urban

if I run the following script:

-snip-
#!/usr/bin/perl

use Encode qw/decode/;

my $string = "B\303\266rsen Feiertag";
print "string=[$string]\n";

my $tmp = decode('utf8', $string, 1);
print "string=[$string], tmp=[$tmp]\n";
-snip-

I get the following output:

-snip-
string=[Börsen Feiertag]
string=[], tmp=[B?sen Feiertag]
-snip-


What happened to $string? There is no mention of side-effects in the Encode
manpage... This only happens when CHECK is set to 1.

I get this behavior on v5.8.8 running on:

- This is perl, v5.10.0 built for i386-linux-thread-multi
- This is perl, v5.8.8 built for i386-openbsd

cheers,

Rob Urban
 
P

Peter Makholm

Robert Urban said:
What happened to $string? There is no mention of side-effects in the Encode
manpage... This only happens when CHECK is set to 1.

The Encoding complex of API's is at best confusing and at worst right
out misleading. What you see fits with the documentation of the decode
method of Encode::Encoding and I have never found the piece of code
that are supposed to convert between the two API's.

//Makholm
 
H

Helmut Wollmersdorfer

Robert said:
my $tmp = decode('utf8', $string, 1);
[...]

What happened to $string? There is no mention of side-effects in the Encode
manpage... This only happens when CHECK is set to 1.

Oh, thx, I didn't know.

----perldoc Encoding----

Encode::LEAVE_SRC
If the "Encode::LEAVE_SRC" bit is not set, but CHECK is, then the
second argument to "encode()" or "decode()" may be assigned to by the
functions. If you’re not interested in this, then bitwise-or the
bitmask with it.

----Quit---------------

this works:

my $tmp = decode('utf8', $string, 9);

HTH

Helmut Wollmersdorfer
 
P

Peter J. Holzer

my $tmp = decode('utf8', $string, 1);

[sets $string to ""]
What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).
This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp
 
S

smallpond

my $tmp = decode('utf8', $string, 1);

[sets $string to ""]
What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).
This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp

According to the source code if check is non-zero it always
overwrites the input string UNLESS check has LEAVE_SRC set.
The documentation implies that check is only used when there
is a bad character in the input, but this is not true.
 
S

sln

my $tmp = decode('utf8', $string, 1);

[sets $string to ""]
What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).
This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp
All programmers know its a feature, there are no bugs!

-sln
 
S

sln

my $tmp = decode('utf8', $string, 1);

[sets $string to ""]
What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).
This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp
All programmers know its a feature, there are no bugs!

-sln

All lapses in logic conciousness are features.

Einstein watched the clock as he sped away from it at/approaching light speed.
Apparently, the light was late getting there.
By the time, his time apparently, he saw the image,
it was an hour later than the actual time from the origination time.

Does that really mean he didn't age relative to the origination clock?

No it doesen't. Delta S of the universe is always >= 0.
Relativity is a ficticous math formula. For if Einstein to go back to where he
started observing the clock, he would be the same age as when he left, otherwise,
he would have to transport over great distances instantaneously.

Have a nice head trip!

-sln
 
S

sln

my $tmp = decode('utf8', $string, 1);

[sets $string to ""]

What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).

This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp
All programmers know its a feature, there are no bugs!

-sln

All lapses in logic conciousness are features.

Einstein watched the clock as he sped away from it at/approaching light speed.
Apparently, the light was late getting there.
By the time, his time apparently, he saw the image,
it was an hour later than the actual time from the origination time.

Does that really mean he didn't age relative to the origination clock?

No it doesen't. Delta S of the universe is always >= 0.
0
Sorry, my clock just isn't ticking. Its never equal from one time to the next.
Measurable? Thats where or equal is asumed in the engineering world, but its a convenience,
not a reality!

-sln
 
S

sln

my $tmp = decode('utf8', $string, 1);

[sets $string to ""]

What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).

This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp
All programmers know its a feature, there are no bugs!

-sln

All lapses in logic conciousness are features.

Einstein watched the clock as he sped away from it at/approaching light speed.
Apparently, the light was late getting there.
By the time, his time apparently, he saw the image,
it was an hour later than the actual time from the origination time.

Does that really mean he didn't age relative to the origination clock?

No it doesen't. Delta S of the universe is always >= 0.
Relativity is a ficticous math formula. For if Einstein to go back to where he
started observing the clock, he would be the same age as when he left,

He would be the same aga as when he left plus the time he was gone. Ie, he
would be the exact same age as if he never left.

-sln
 
S

sln

my $tmp = decode('utf8', $string, 1);

[sets $string to ""]

What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).

This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp
All programmers know its a feature, there are no bugs!

-sln

All lapses in logic conciousness are features.

Einstein watched the clock as he sped away from it at/approaching light speed.
Apparently, the light was late getting there.
By the time, his time apparently, he saw the image,
it was an hour later than the actual time from the origination time.

Does that really mean he didn't age relative to the origination clock?

No it doesen't. Delta S of the universe is always >= 0.
Relativity is a ficticous math formula. For if Einstein to go back to where he
started observing the clock, he would be the same age as when he left,

He would be the same aga as when he left plus the time he was gone. Ie, he
would be the exact same age as if he never left.

-sln

Because, when approach the speed of light back towards the clock, you are going
faster than the speed of light relative to the clock.

The images are speeded up, time quickens, the clock is in fast motion right before
your eyes. Your youth disapears in relative motion against light. You lose, sorry.

-sln
 
S

sln

On Thu, 23 Apr 2009 15:01:31 -0700, (e-mail address removed) wrote:


my $tmp = decode('utf8', $string, 1);

[sets $string to ""]

What happened to $string? There is no mention of side-effects in the Encode
manpage...

There is, but only for CHECK == FB_QUIET or FB_WARN, not for FB_CROAK
(1).

This only happens when CHECK is set to 1.

Nope, it also happens if CHECK is set to 4 (FB_QUIET) or 6 (FB_WARN).
But there it is documented.

I'm not sure if this is a bug or an (undocumented) feature.

hp
All programmers know its a feature, there are no bugs!

-sln

All lapses in logic conciousness are features.

Einstein watched the clock as he sped away from it at/approaching light speed.
Apparently, the light was late getting there.
By the time, his time apparently, he saw the image,
it was an hour later than the actual time from the origination time.

Does that really mean he didn't age relative to the origination clock?

No it doesen't. Delta S of the universe is always >= 0.
Relativity is a ficticous math formula. For if Einstein to go back to where he
started observing the clock, he would be the same age as when he left,

He would be the same aga as when he left plus the time he was gone. Ie, he
would be the exact same age as if he never left.

-sln

Because, when approach the speed of light back towards the clock, you are going
faster than the speed of light relative to the clock.

The images are speeded up, time quickens, the clock is in fast motion right before
your eyes. Your youth disapears in relative motion against light. You lose, sorry.

-sln

I hate to tell ya but, Relativity is just relative to light direction, entrophy is preserved though (almost),
otherwise traveling at the speed of light, mathmatecally, would not see a change in time nor energy.
If Einstein were right, Delta S of the universe could be 0 from one time to another, which is impossible.
-sln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top