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.
Output: