* Karl Williamson <public@khwilliamson.com> [2010-01-04 20:05]:
> People on this list have said that bytes.pm is legitimate when
> manipulating binary data.
I don’t see how. There is no real reason why strings with binary
data should get the UTF8 flag set. But they legitimately might
(eg. some XS code might unconditionally produce upgraded strings,
for ease of implementation). And I cannot think of any case where
*ignoring* the state of the UTF8 flag is the correct thing to do
in application code.
my $img = slurp 'foo.png';
my $copy = $img;
utf8::upgrade($copy);
Now the UTF8 flag on $copy is set but on $img is not.
If you `eq` these strings, you get true. If you print them, both
will produce the same output.
There is no reason to care about whether either of them has the
UTF8 flag set. They are the same string. Internally they may use
different storage formats, but why would you care?
Yet `bytes::length` and other bytes.pm operations will yield
different results for them. Quite simply the `bytes` pragma does
nothing more than force a solid abstraction to leak.
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
Thread Previous
|
Thread Next