Skip to content
Related Articles

Related Articles

Perl | oct() Function

View Discussion
Improve Article
Save Article
  • Last Updated : 25 Jun, 2019

oct() function in Perl converts the octal value passed to its respective decimal value. For example, oct(‘1015’) will return ‘525’. This function returns the resultant decimal value in the form of a string which can be used as a number because Perl automatically converts a string to a number in numeric contexts. If the passed parameter is not an octal number then the result will be 0.

Syntax: oct(oct_value)

oct_value: Octal number which is to be converted to decimal

the octal value converted to decimal value

Example 1:

#!/usr/bin/perl -w
# Converting and printing 
# the decimal value
print("oct(31) ", oct('31'), "\n");
print("oct(50) ", oct('50'), "\n");


oct(31) 25
oct(50) 40

Example 2:

#!/usr/bin/perl -w
# Converting and printing 
# the decimal value
print("oct(106) ", oct('106'), "\n");
print("oct(125) ", oct('125'), "\n");


oct(106) 70
oct(125) 85
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!