If the input string is made of digits, you will see an hex like that you're describing. Consider that in ASCII the digits characters range from decimal 48, which is 0x30, to decimal 57, which is 0x39.
If you have numbers that you want to treat like integers, and they're in the range 0-255, you can put a chr in the chain:
#!/usr/bin/perl
use strict;
use warnings;
my @values = (0, 1, 5, 25, 100, 200, 255);
print join(", ", map { unpack "H*", chr } @values), $/;
__END__
00, 01, 05, 19, 64, c8, ff
You may also consider
printf/
sprintf with the
X indicator:
#!/usr/bin/perl
use strict;
use warnings;
my @values = (0, 1, 5, 25, 100, 200, 255, 500, 1000);
print join(", ", map { sprintf "%X", $_ } @values), $/;
__END__
0, 1, 5, 19, 64, C8, FF, 1F4, 3E8
Note that this second solution works well with numbers beyond 255. You can also pad with zeroes on the left, just look in the docs for
sprintf.
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
Don't fool yourself.
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.