in reply to String adding

tim0304,
I think this does what you want.
my $hex = '0FB0306F207265616420746869733F'; my $sum; $sum += hex($_) for unpack('A2' x (length($hex) / 2), $hex); print $sum;

Cheers - L~R

Replies are listed 'Best First'.
Re^2: String adding
by Roy Johnson (Monsignor) on Nov 11, 2005 at 19:20 UTC
    $sum += hex($_) for $hex=~/../g;
    Is a bit less intimidating, IMO.

    Caution: Contents may have been coded under pressure.
Re^2: String adding
by ikegami (Patriarch) on Nov 11, 2005 at 19:14 UTC
    and save the result in Hex to a variable.

    Add:

    $sum_as_hex = sprintf('%X', $sum);
Re^2: String adding
by sauoq (Abbot) on Nov 11, 2005 at 20:01 UTC
    unpack('A2' x (length($hex) / 2), $hex);

    I'd rewrite that as

    unpack('(A2)*', $hex);

    -sauoq
    "My two cents aren't worth a dime.";
    
      That fails in 5.6.x. The parens were added to pack in 5.8.0