Hi

I have a text file containing hex strings such as: 12 34 56 78 90 ab cd ef
now I want to change these hex strings to sequence of bytes with the
relative value of 0x12 0x34 0x56 ....

bellow are my codes

use strict;
use warnings;
sub proc_file
{
    my ($in, $out) = @_;
    open my $fin, '<', $in or die "$!, $in";
    open my $fout, '>', $out or die "$!, $out";
    while(<$fin>)
    {
        my @values  = split /\s+/;
        print $fout join '' , map { pack 'H*', $_} @values;   # method 1
        print $fout pack 'H*', join '', @values;                   # method
2
        print $fout pack 'H*', @values;                            # method
3
    }
}

proc_file @ARGV;


The result is that, both method 1 and method 2 works OK, but with method 3,
I only get the first byte. For example,
if @values is 12 34 56 78
pack 'H*', @values will get a string with only one byte 0x12
from perlfun, I found that the pack function will gobble up that many values
from the LIST except for some types, and 'H' is one of these types.
so, if I use
pack 'H*H*H*H*', @values;
I will get the correct result of 4 bytes 0x12 0x34 0x56 0x78

My question is, does there exist some other more simple way to accomplish
this transfrom, for example, just one modifier to tell the pack to use all
items of the LIST?

Thanks & Best Regards
Albert


-- 
missing the days we spend together

Reply via email to