Reads any kind of integer. : oct « Data Type « Perl






Reads any kind of integer.

   
#!/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"); 

   
    
    
  








Related examples in the same category

1.Convert a number with the hex() or oct()
2.Illegal octal number: with 8 inside
3.Octal number
4.Octal numerals starting with 0x
5.Using oct function to convert number to octal numbers
6.oct("178")
7.octal data