programming-examples/perl/Datatype/Reads any kind of integer.pl

11 lines
257 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/local/bin/perl
$integer = <STDIN>;
chop ($integer);
if ($integer !~ /^[0-9]+$|^0[xX][0-9a-fa-F]+$/) {
die ("$integer is not a legal integer\n");
}
if ($integer =~ /^0/) {
$integer = oct ($integer);
}
print ("$integer\n");