Open In App

Perl | oct() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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:




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


Output:

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");


Output:

oct(106) 70
oct(125) 85

Last Updated : 25 Jun, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads