That is what regular expressions are for:
local $_ = <STDIN>; chomp; my $hexnum = undef; $hexnum = eval "0x$1" if (m/^(?:0[xX])?([[:xdigit:]]+)$/); die "bad input" unless defined $hexnum;
Do not assume that the input meets your constraints — verify that the input meets your constraints! :-)
In reply to Re^6: hex numbers
by jcb
in thread hex numbers
by LloydRice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |