Skip to content
Related Articles

Related Articles

Perl | oct() Function
  • 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)

Parameter:
oct_value: Octal number which is to be converted to decimal

Returns:
the octal value converted to decimal value

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

oct(31) 25
oct(50) 40

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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