in reply to pack on unpack with same template

G'day jjmoka,

Your assumption seems reasonable. Here's a test script:

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;

use Test::More;

my @test_strings = qw{ abc абв αβγ 🌌🪐🚀  🏻🏼🏽 𓀀𓀁𓀂 ◌◌◌̂ };

plan tests => 0+@test_strings;

ok $_ eq pack('U0C*', unpack('U0C*', $_)) for @test_strings;

Output:

1..7 ok 1 ok 2 ok 3 ok 4 ok 5 ok 6 ok 7

As you suggest, there may be special cases. I couldn't think of any off the top of my head; other monks may know of some. You can just add more strings to @test_strings to test them (without needing to change anything else in the test script).

You just said "I've found this code". Knowing something about the source and context of that code may provide scope for better answers.

— Ken

Replies are listed 'Best First'.
Re^2: pack on unpack with same template
by jjmoka (Beadle) on Jul 28, 2021 at 06:42 UTC
    Thank you. I did some testing myself (even though less elegant). I can fill the gap of context but unfortunately the information doesn't help. This is actually just code I've found. Git points me to a 7 years old commit when the repo was moved from svn to git. The real author is only guessable but anyhow all these people already went coding somewhere else. For who is left with it, there is always, at least, this monastery to act like a lighthouse in the darkness.