in reply to pack on unpack with same template

AFAICT, the effect of pack('U0C*', unpack('U0C*', ...)) is the same as utf8::upgrade. See also What does utf8::upgrade actually do.

use warnings; use strict; use Devel::Peek; my @tests = ( "Hello", "Hell\xF6", "\N{U+20AC}", "\xE2\x82\xAC", ); for my $in (@tests) { my $out = pack('U0C*', unpack('U0C*', $in)); print STDERR "##### ##### ##### pack/unpack ##### ##### #####\n"; Dump($in); Dump($out); print STDERR "##### upgrade #####\n"; Dump($in); utf8::upgrade($in); Dump($in); }

Replies are listed 'Best First'.
Re^2: pack on unpack with same template
by ikegami (Patriarch) on Jul 28, 2021 at 09:31 UTC

    This is what I suspected it was doing when I saw the question. I did not have a chance to verify it.

    Seeking work! You can reach me at ikegami@adaelis.com

      Yup, confirmed that changing to the "upgraded" internal storage format is the only effect other than making a copy.

      Seeking work! You can reach me at ikegami@adaelis.com