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 Like