Perl | log() Function Last Updated : 25 Jun, 2019 Comments Improve Suggest changes Like Article Like Report log() function in Perl returns the natural logarithm of value passed to it. Returns $_ if called without passing a value. log() function can be used to find the log of any base by using the formula: Syntax: log(value) Parameter: value: Number of which log is to be calculated Returns: Floating point number in scalar context Example 1: Perl #!/usr/bin/perl -w # Calculating log of base 10 # using log function print "log10(2): ", log10(2), "\n"; print "log10(7): ", log10(7), "\n"; print "log10(9): ", log10(9), "\n"; # Function for log10 calculator sub log10 { my $n = shift; # using pre-defined log function return log($n) / log(10); } Output: log10(2): 0.301029995663981 log10(7): 0.845098040014257 log10(9): 0.954242509439325 Example 2: Perl #!/usr/bin/perl -w # Calculating log of different # base using log function print "log3(2): ", log3(2), "\n"; print "log5(7): ", log5(7), "\n"; print "log2(9): ", log2(9), "\n"; # Function for log3 calculator sub log3 { my $n = shift; # using pre-defined log function return log($n) / log(3); } # Function for log5 calculator sub log5 { my $n = shift; # using pre-defined log function return log($n) / log(5); } # Function for log2 calculator sub log2 { my $n = shift; # using pre-defined log function return log($n) / log(2); } Output: log3(2): 0.630929753571457 log5(7): 1.20906195512217 log2(9): 3.16992500144231 Comment More infoAdvertise with us Next Article Perl | log() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Perl-Math-Functions Similar Reads Perl | exp Function The exp function in Perl calculates "e" raised to the power of the real number taken as the parameter. Here "e" is Eulerâs Number or the base of the Natural system of logarithms or commonly known as an irrational number that approximates to 2.718281828, and is one of the most important mathematical 2 min read Perl | abs() function This function returns the absolute value of its argument. If a pure integer value is passed then it will return it as it is, but if a string is passed then it will return zero. If VALUE is omitted then it uses $_ Syntax: abs(VALUE) Parameter: VALUE: It is a required number which can be either positi 2 min read Perl | cos() Function This function is used to calculate cosine of a VALUE or $_ if VALUE is omitted. The VALUE should be expressed in radians. Syntax: cos(VALUE) Parameters: VALUE in the form of radians Returns: Function returns cosine of VALUE. Example 1: Perl #!/usr/bin/perl # Calling cos function $var = cos(5); # Pri 1 min read Perl | sin() Function This function is used to calculate sine of a VALUE or $_ if VALUE is omitted. This function always returns a floating point. Syntax: sin(VALUE) Parameters: VALUE in the form of float Returns: Function returns sine of VALUE. Example 1: Perl #!/usr/bin/perl # Calling sin() function $var = sin(5); # Pr 1 min read Perl | File I/O Functions File handling in Perl is used to read data from an external file or to write data into an external file. This is very useful as it provides a platform to permanently store and retrieve data from files. File Handle A FileHandle associates a name to an external file, that can be used until the end of 4 min read Perl | sqrt() Function Many times it happens that while solving mathematical expressions we require to calculate the square root of a number. To solve this issue, like other programming language Perl provides us with a built-in function sqrt() which can be used to calculate the square root of a number. Syntax: sqrt value 1 min read Perl | tell() Function tell() function in Perl is used to get the position of the read pointer in a File with the use of its FileHandle. If no FileHandle is passed then it returns the position within the most recent accessed file. Syntax: tell(FileHandle) Parameter: FileHandle: Filehandle of the file to be accessed. Retur 1 min read Perl | sleep() Function sleep() function in Perl is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds or forever if parameter is not specified. The sleep( ) function accepts seconds as a parameter and returns the same on success. Syntax: sleep(seconds) Returns: 1 min read Perl | Useful String functions A string in Perl is a scalar variable and start with a ($) sign and it can contain alphabets, numbers, special characters. The string can consist of a single word, a group of words or a multi-line paragraph. The String is defined by the user within a single quote (â) or double quote (â). Perl provid 3 min read Formats in Perl Formats are the writing templates used in Perl to output the reports. Perl has a mechanism which helps in generating simple reports and charts. Instead of executing, Formats are declared, so they may occur at any point in the program. Formats have their own namespace apart from the other types in Pe 5 min read Like