oct Function in Perl

What is oct Function in Perl?


The oct function interepts the EXPR as an octal string to return the corresponding decimal value, if prepended with "0x" it ineterepts as a hexadecimal string, if prepended with "0b" it interepts as a binary string, the leading white spaces are ignored.


oct EXPR;

Example :

#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$x = oct("36");
print "$xn";
$y = oct("0x36");
print "$yn";
$z = oct(042);
print "$zn";
Result :

30 54 28

In the above example the respective decimal values for the octal values passed to the oct function is displayed.

Ask Questions

Ask Question