in reply to String to Byte array

Assuming the key contains valid 2digit hex numbers:

use strict; use warnings; my $key = "A21B12C212AD12FF"; my @key = map hex, $key =~ /../g; print "@key\n";

HELP: How to do this with unpack? All my attempts are failing...

Replies are listed 'Best First'.
Re^2: String to Byte array
by BrowserUk (Patriarch) on Sep 19, 2013 at 20:50 UTC

    What the OP probably needs, rather than an array of integers, is a binary string of unsigned chars derived from the hex string input.

    That is done using pack, not unpack:

    print pack 'H*', "A21B12C212AD12FF";; ó←↕┬↕¡↕ 

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks that helped me to get the same output as C# code. Perl Rules :)