How To Tutorial: Perl Scalar and String Functions


"Find Out How You Can Use The Perl Scalar and String Functions In The Most Frequent Situations You’re Confronted With When You Write A Perl Script … See In Minutes A Lot Of Complete Code Solutions From Which You Can Copy Pieces of Code And Paste Them Directly In Your Own Script"
The "Perl Scalar and String Functions - How To Tutorial" eBook answers the most frequently questions regarding the use of the scalar and string functions in the Perl language. You’ll find interesting and complete examples about why, how and where you can use these functions in a Perl script.


The functions described in this eBook include: chomp, chop, chr, crypt, hex, index, lc, lcfirst, length, oct, ord, pack, q, qq, reverse, rindex, sprintf, substr, tr///, uc, ucfirst and y///.

For every function, I presented the syntax forms and a brief description. This was necessary to help you better understand how to use the topics. If you want a complete description of these functions, you should go for additional information to the Perl official site by following the link perldoc.

If you take your time to skim through the Table of Contents of this eBook, you’ll see what you should expect to find here. From using the chomp function to remove the ending newline from an input string, manipulating or querying information about a string, to mastering data conversions from a format to another, you’ll find here a lot of commented examples to help you find a quick solution to your problem.

The examples included in this eBook are not only about the scalar and string functions, but also show you how to use these functions together with the operators, special variables, statements, regular expressions and with simple or complex data structures.

To give you an example, the use of the chomp function is illustrated in almost 50 commented script examples covering more than 25 situations where you can use it.

Complete solutions are provided for almost all the examples. Each example can be tested, modified and run individually. Every example shows you a way to resolve a specific problem, allowing you to find out a quick answer to your problem or question.


Now You Can Save Time And Find In Minutes The Answer To Your Question

If you want to improve your programming skill regarding the use of the scalar and string functions in different contexts, you’ll find real help in this eBook. I chose for you the most frequent questions and I illustrated them with the appropriate examples.

Well, there are lots of electronic books in terms of Perl around there, why a new eBook? What is it so interesting?

If you look at the Table of Contents, it could happen that you don’t notice its great characteristics and how I built it. Frankly, you did it, not me! I answered your queries only.

Please wait, do not go, no kidding, I am really serious. Let me explain.

I'll give an example, using the chomp function. If you have a look at my Table of Contents, section 3.1. is about the chomp function and includes 28 different subtopics related to this function.

I got on my site thousands of searches regarding how to use the chomp function in Perl. I chose the most common and I illustrated them with fully commented examples. The 28 subtopics above are the most common topics on the use of chomp in Perl.

There are great chances to find the appropriate answer in this eBook for any question regarding the use of the chomp function in Perl!

To be more explicit look at the next table and see what I mean:

Your search query
my eBook section
chomp($name = )3.1.11.
chomp hash keys and values3.1.7.
chomp array ref3.1.10.
difference between chop and chomp3.1.28.
perl chomp binary file3.1.27.
while chomp3.1.15.
perl slurp chomp to array3.1.5.
perl chomp($_)3.1.8.
chomp stdin one line3.1.12.
. . .

and the list could continue.

But there is much more than you can see in the eBook Table of Contents. For example, a lot of snippets throughout this eBook are using the regular expressions and you can’t see this by skimming the Table of Contents.

It could happen that not all topics are covered in full, but this version will improve soon so that you can download for free the upgrade versions (as I mention below, you can download this ebook nine times, using the same link).

Of course you can continue searching through the forums to find the answer of your question but in this case you need to choose, test and interpret yourself the information provided in the forums.

In this eBook I give you a lot of working code that you can implement in minutes in your script. And not only that, all the provided snippet codes are fully functional, i.e can be copied and tested in your command line window. Next, they can be integrated in a script and uploaded to your site.

In order to make the scripts very easy to understand, I commented in detail each code snippet so you will not have any problem to understand and implement it.

Table Of Contents

I think you can use this eBook to find out very fast how to use the Perl scalar and string functions in different situations.

Please take a look at the table of contents to see what I mean:

1.Copyright
2.Introduction
  2.1.How to run the examples included in this eBook
    2.1.1.How to run the script in Windows
    2.1.2.How to run the script in Linux
3.Perl scalar and string functions
  3.1.Perl chomp function
    3.1.1.The syntax forms
    3.1.2.How to use the return value of the chomp function
    3.1.3.How to chomp a string variable
    3.1.4.How to chomp an array
    3.1.5.Read file as a chomped array
    3.1.6.How to chomp the array elements one by one
    3.1.7.How to chomp a hash
    3.1.8.How to use chomp and the special variable $_
    3.1.9.How to use chomp with $/ and set $/ to different strings
    3.1.10.How to chomp a reference variable (scalar, array or hash)
    3.1.11.How to use chomp when reading from STDIN
    3.1.12.How to use chomp in a single line along with STDIN
    3.1.13.How to use chomp to remove all the trailing newlines from a string
    3.1.14.How to use chomp with foreach statement
    3.1.15.How to use chomp with while statement and STDIN
    3.1.16.How to use chomp along with defined and STDIN
    3.1.17.How to use chomp with last, next and redo loop controls
    3.1.18.A chomp, index, lc, uc, unshift and push example
    3.1.19.How to chomp large data
    3.1.20.How to use chomp and push
    3.1.21.How to use chomp and split
    3.1.22.How to use chomp, lc and if on STDIN
    3.1.23.How to use chomp and hex
    3.1.24.How to chomp complex data structures using a recursive subroutine
    3.1.25.How to use chomp when reading multiline strings
    3.1.26.How to remove LF or CR at the end of a line read from a text file
    3.1.27.How to use chomp with a binary file
    3.1.28.Which is the difference between chop and chomp
  3.2.Perl chop function
    3.2.1.The syntax forms
    3.2.2.How to chop the first character of a string
    3.2.3.How to use chop with a string variable
    3.2.4.How to use chop with arrays
    3.2.5.How to use chop with hashes
    3.2.6.How to use chop with $_ and foreach
  3.3.Perl chr function
    3.3.1.The syntax forms
    3.3.2.A simple example
    3.3.3.Convert an ASCII code string into a character string
    3.3.4.Convert a hexadecimal string into a character string
  3.4.Perl crypt function
    3.4.1.The syntax forms
    3.4.2.A simple example
    3.4.3.How to use random characters for the salt
    3.4.4.How to check a user password in Linux
  3.5.Perl hex function
    3.5.1.The syntax forms
    3.5.2.How to convert a hexadecimal number into a decimal one
    3.5.3.How to convert a decimal value into another numeration base
    3.5.4.How to convert a scalar string into a hexadecimal format
  3.6.Perl index function
    3.6.1.The syntax forms
    3.6.2.How to check if a string is a substring of another
    3.6.3.How to find the leftmost occurrence of a substring in a string
    3.6.4.How to find all the occurrences of a substring in a string
    3.6.5.How to count all the matches of a substring in a string
    3.6.6.How to remove the trailing spaces using the index function
  3.7.Perl lc function
    3.7.1.The syntax forms
    3.7.2.How to convert a string in lowercase
    3.7.3.How to compare two strings case insensitive
    3.7.4.How to convert all the array elements in lowercase
  3.8.Perl lcfirst function
    3.8.1.The syntax forms
    3.8.2.How to convert the first character of a string in lowercase
  3.9.Perl length function
    3.9.1.The syntax forms
    3.9.2.How to find the number of characters of a string variable
    3.9.3.How to find the length of a string in bytes
    3.9.4.Sort the words of a string in a descending length order
    3.9.5.How to process a string one character at a time
    3.9.6.Get the string length of the shortest/longest string in an array
    3.9.7.How to use the length function in a foreach loop
    3.9.8.Sort the elements of an array by string length
    3.9.9.Sort the elements of a hash by the length of the values
    3.9.10.Sort the elements of a hash by the length of the keys
    3.9.11.How to find the length of an AOA (array of arrays)
    3.9.12.How to find the length of an HOH (hash of hashes)
  3.10.Perl oct function
    3.10.1.The syntax forms
    3.10.2.Simple examples
    3.10.3.Octal File Permissions and the Perl oct function
  3.11.Perl ord function
    3.11.1.The syntax forms
    3.11.2.A simple example
    3.11.3.Convert a character string into an ASCII code array
    3.11.4.Convert a character string into a hexadecimal string
    3.11.5.How to use ord and pack to convert from binary to decimal
  3.12.Perl pack function
    3.12.1.The syntax form
    3.12.2.A string with binary data will be null padded [ a ]
    3.12.3.A text (ASCII) string will be space padded [ A ]
    3.12.4.A bit string (ascending bit order inside each byte) [ b ]
    3.12.5.A bit string (descending bit order inside each byte) [ B ]
    3.12.6.A signed char (8-bit) value [ c ]
    3.12.7.A unsigned char (octet) value [ C ]
    3.12.8.A double-precision float in the native format [ d ]
    3.12.9.A single-precision float in the native format [ f ]
    3.12.10.A hex string (low nibble first) format [ h ]
    3.12.11.A hex string (high nibble first) format [ H ]
    3.12.12.A signed integer value [ i ]
    3.12.13.An unsigned integer value [ I ]
    3.12.14.A signed long (32-bit) value [ l ]
    3.12.15.An unsigned long value [ L ]
    3.12.16.An unsigned short (16-bit) in a big-endian order [ n ]
    3.12.17.An unsigned long (32-bit) in a big-endian order [ N ]
    3.12.18.A signed short (16-bit) value [ s ]
    3.12.19.An unsigned short value [ S ]
    3.12.20.A Unicode character number [ U ]
    3.12.21.An unsigned short (16-bit) in little-endian order [ v ]
    3.12.22.An unsigned long (32-bit) in little-endian order [ V ]
    3.12.23.A null byte [ x ]
    3.12.24.Back up a byte [ X ]
    3.12.25.How to reverse the bits in each character of a string
    3.12.26.Short dictionary
  3.13.Perl q/STRING/
  3.14.Perl qq/STRING/
  3.15.Perl reverse function
    3.15.1.The syntax forms
    3.15.2.Simple examples
    3.15.3.Get a sentence with the words in an inverted order
    3.15.4.Check up if a string is palindrome
  3.16.Perl rindex function
    3.16.1.The syntax forms
    3.16.2.How to check if a substring is included in a string
    3.16.3.How to find the rightmost occurrence of a substring in a string
    3.16.4.How to get all the occurrences of a substring in a string
  3.17.Perl sprintf function
    3.17.1.The syntax form
    3.17.2.sprintf versus printf
    3.17.3.How to limit the number of decimal places in your numbers
    3.17.4.How to round a certain number of decimals
    3.17.5.How to convert from decimal to hexadecimal
    3.17.6.How to convert from decimal to octal
    3.17.7.How to convert from decimal to binary
    3.17.8.How to pad a string with blanks
    3.17.9.How to pad a number on the left with zeroes
    3.17.10.How to expand variables in text strings
    3.17.11.How to format floating-point numbers
    3.17.12.How to format the local time in a scalar variable
    3.17.13.How to use sprintf with regexp
  3.18.Perl substr function
    3.18.1.The syntax forms
    3.18.2.How to use substr to extract a substring from a string
    3.18.3.How to use substr like a lvalue
    3.18.4.Replace a substring with a different substring in a string
    3.18.5.How to get the column fields from a flat file database
    3.18.6.How to pad a string left and right with any character
    3.18.7.How to convert between number representations
    3.18.8.Split a string into fixed-length parts
    3.18.9.How to extract a substring between two other substrings
    3.18.10.The substr function and the =~ binding operator
  3.19.Perl tr/// operator
    3.19.1.The syntax form
    3.19.2.How to use tr/// with the =~ binding operator
    3.19.3.How to use tr/// with $_
    3.19.4.How to use tr/// with the complement (c) modifier
    3.19.5.How to use tr/// with the delete (d) modifier
    3.19.6.How to use tr/// with the squash (s) modifier
    3.19.7.How to use tr/// with more than one modifier
    3.19.8.How to use variables in tr///
    3.19.9.How to use tr/// for counting characters
    3.19.10.Which is the difference between tr/// ans s///
  3.20.Perl uc function
    3.20.1.The syntax forms
    3.20.2.How to convert a string in uppercase
    3.20.3.How to compare two strings case insensitive
    3.20.4.How to convert all the array elements in uppercase
  3.21.Perl ucfirst function
    3.21.1.The syntax forms
    3.21.2.Convert the first character of a string in uppercase
    3.21.3.How to capitalize all words in a string
  3.22.Perl y/// operator

And as a bonus, I give you a "Perl Glossary" eBook to help you better understand the topics included in my tutorial.

A Sample From My eBook

To have a first look about what you could expect to find inside, I invite you to download for free a sample from my "Perl Scalar and String Functions - How To Tutorial" and "Perl Glossary" eBooks.

What You’ll Get
  • A 163 page "Perl Scalar and String Functions - How to Tutorial" eBook (PDF format)
  • I prepared a bonus for you – an additional glossary eBook (PDF format) meant to help you understand the topics included in this eBook tutorial
  • After I’ll modify or extend the eBook (maybe at your suggestion), the download link provided will let you download for free the upgraded version - please note that the download link will expire after 9 attempts
I intend to enlarge this eBook with a lot of other useful examples, but I am going to increase the price, too. Buy this eBook now! And you can download it for maximum 9 times, having free access to the following upgrades.If you consider that this book is valuable or you have some suggestions to improve its content, please send me some feedback through my contact page.



 Testimonials 

Read what others have to say about my eBooks Collection!


To order your personal copy, click here to receive instant download instructions:

Buy Now

12.50 US$ only

9.75 US$ only (limited time offer)


You Are Secure!

By clicking the "Buy Now" button, you will be taken to the ultra secure online payment method using PayPal.

I will not sell or pass on your details to anyone. Your information and the fact that you contacted me are confidential.

I think this price must be very convenient to you. I try to keep the price as low as I can in order for many people to afford it. But I can’t guarantee this low price for a long time - especially in the case I'll extend the eBook, so do yourself a favor and grab it now!

30-Day, 100% unconditional money-back guarantee

If for any reason you don’t think this eBook is helpful to you in any way, I offer an unconditional, no-questions-asked, 30-Day 100% refund. You can’t lose on this deal.

PS. Don’t forget that this eBook will help you with a lot of examples about how to use one of the most important Perl topics: the string functions. You’ll use the Perl string functions again and again, with other Perl functions, statements, strings, arrays or hashes and you need to find working examples quickly about how to implement it.

I am a computer professional and my background in the computer science field and at the University allows me to offer you a valuable resource that can make your programming tasks easier.

PPS. This eBook contains almost 250 commented script examples covering more than 150 situations where you can see how the Perl scalar and string functions work.

Buy it now! It is a valuable resource and you have no risk. If you consider that you don’t need it, I’ll refund your money (in this case use my contact form to let me know).


Special offer

I'm gonna make you an amazing offer you can't refuse - get all my eBooks for the incredible price of 14.99 US$ only:


and save 78% ($52.81) of the real price.

These eBooks contain more than

  • 700 pages and
  • 1000 commented script examples.

To order the eBooks package, click here to receive instant download instructions:
Buy Now

14.99 US$ only (limited time offer)

30-Day, 100% unconditional money-back guarantee

If for any reason you don’t think these eBooks are helpful to you in any way, I offer an unconditional, no-questions-asked, 30-Day 100% refund. You can’t lose on this deal.


The eBooks were archived into a zip file. After you download the archive file, you need to extract the PDF files from it using WinZip or any other unzipping program.

The eBooks were converted in a PDF format, so you need Adobe Acrobat Reader to read them. Download the free version here:



return from "Perl Scalar and String Functions - How To Tutorial" to "Perl How To Tutorials"