Perl | sprintf() Function Last Updated : 07 May, 2019 Comments Improve Suggest changes Like Article Like Report sprintf() function in Perl uses Format provided by the user to return the formatted string with the use of the values in the list. This function is identical to printf but it returns the formatted string instead of printing it. Syntax: sprintf Format, List Returns: a formatted scalar string Example 1: Perl #!/usr/bin/perl -w # Formatting the string using sprintf $text1 = sprintf("%8s", 'Geeks'); $text2 = sprintf("%-8s", 'Geeks'); # Printing the formatted string print "$text1\n$text2"; Output: Geeks Geeks Example 2: Perl #!/usr/bin/perl -w # Formatting the string using sprintf $text1 = sprintf("%03d", '7'); $text2 = sprintf("%03d", '123'); $text3 = sprintf("%04d", '123'); # Printing the formatted string print "$text1\n$text2\n$text3"; Output: 007 123 0123 Comment More infoAdvertise with us Next Article Perl | sprintf() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Perl-String-Functions Similar Reads Perl | split() Function split() is a string function in Perl which is used to split or you can say to cut a string into smaller sections or pieces. There are different criteria to split a string, like on a single character, a regular expression(pattern), a group of characters or on undefined value etc.. The best thing abou 8 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 | 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 | srand() Function The srand() function in Perl helps rand() function to generate a constant value each time the program is run. This srand() function uses the same parameter each time the rand() function is called for getting constant random value. Syntax: srand(seed) Parameters: seed : It is an integer value. Return 3 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 Perl | return() Function return() function in Perl returns Value at the end of a subroutine, block, or do function. Returned value might be scalar, array, or a hash according to the selected context. Syntax: return Value Returns: a List in Scalar Context Note: If no value is passed to the return function then it returns an 2 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 | Subroutines or Functions A Perl function or subroutine is a group of statements that together perform a specific task. In every programming language user want to reuse the code. So the user puts the section of code in function or subroutine so that there will be no need to write code again and again. In Perl, the terms func 2 min read Perl | ord() Function The ord() function is an inbuilt function in Perl that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string. Syntax: ord string Parameter: This function accepts a single par 1 min read Perl | oct() Function 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 nume 1 min read Like