in reply to Basic transformations

I am having another problem with this in practice. My code seems to work, but it is producing some error messages I don't understand.
A snippet of the actual code in use:
#!/usr/bin/perl -w use strict; open ( SOMEFILE, '<', "$ARGV[0]" ) or die "Can't open $ARGV[0] for reading.\n"; while (defined($_ = <SOMEFILE>)) { my @cbytes = split; my @hbytes = map(hex, @cbytes); my $hstring = pack('c*', @hbytes); } close SOMEFILE;
One line of data (remember, I only used printable characters for the example):
99 00 00 00 dd 02
And the output:
Character in 'c' format wrapped in pack at ./test.pl line 11, <SOMEFIL +E> line 1. Character in 'c' format wrapped in pack at ./test.pl line 11, <SOMEFIL +E> line 1.
Can someone tell me what is going on here? Thanks.

Replies are listed 'Best First'.
Re^2: Basic transformations
by BrowserUk (Patriarch) on Nov 30, 2010 at 01:34 UTC

    Use the pack template 'C*' instead of 'c*'. The latter only handles byte values up to 127, the former handles up to 255.

      By the way, you could speed up your processing of that data enormously by skipping the split multiple maps over hex and chr et al. by using:

      $s = '48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21';; $s =~ tr[ ][]d; print pack 'H*', $s;; Hello, world!
      Thanks. I don't know how I missed that.