After studying your updates, private messages, and documentation for 'pack', I was able to fix my previous code by packing one extra (arbitrary) character, and not unpacking it. However, I noticed that the 'pack' was overkill. I could concatenate three extra nulls to the end of the original ASCII string and unpack as much as necessary. The length ($l) has to be twice what it was before because now I am unpacking two hex characters for every one ASCII character that I had been packing.
use strict;
use warnings;
use Test::More tests=>4;
my @examples = (
[qw( example. 6578616d706c652e )],
[qw( example.1 6578616d706c652e31000000)],
[qw( example.12 6578616d706c652e31320000)],
[qw( example.123 6578616d706c652e31323300)],
);
foreach my $example(@examples) {
my ($Origin_Host_CER, $required) = @$example;
my $l = 8*int((length($Origin_Host_CER)+3)/4);
my $result = unpack("H$l", $Origin_Host_CER . "\x00" x 3);
is($result, $required, $Origin_Host_CER);
}
RESULTS
1..4
ok 1 - example.
ok 2 - example.1
ok 3 - example.12
ok 4 - example.123
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.