Perl – Changing the Input Line Separator and Using the “chomp” Function

In this blog I demonstrate how you can change the input line separator in Perl and use Perl’s “chomp” function. Note, the input line separator is operating system dependent; see the following prior blog of mine where I discuss this subject in more detail: Unix shell script – convert Mac ASCII file to Unix ASCII file. The “chomp” function checks to see if the last character of a string or list of strings matches the line separator character stored in the ‘$/’ system variable; if there is a match, the character is deleted.

Changing the ‘$/’ system variable is fairly easy as demonstrated below. Note, when used in list context, the “chomp” function deletes the line separator character from every element of the list.

Changing the input line separator and using the "chomp" function

Changing the input line separator and using the "chomp" function



Output:
Output after using the "chomp" function

Output after using the "chomp" function


This entry was posted in Perl, Programming Languages, Technology and tagged , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


− one = 4