The chomp() function in Perl is used to remove the last trailing newline from the input string.
String : Input String whose trailing newline is to be removed
Returns: the total number of trailing newlines removed from all its arguments
Chopped String is : GfG is a computer science portal Number of Characters removed : 1
In the above code, it can be seen that input string containing a newline character (\n) which is removed by chomp() function.
Chopped String is : Geeks for Geeks Welcomes you all Number of Characters removed : 2
In the above code, it can be seen that the input string1 containing two newline characters (\n\n) out of which only last newline character is removed by chomp() function and second last newline character is utilized which can be seen in the output.
- Perl | Basic Syntax of a Perl Program
- Perl Tutorial - Learn Perl With Examples
- Perl | split() Function
- Perl | chop() Function
- Perl | rename() Function
- Perl | undef and the defined function
- Perl | cos() Function
- Perl | sin() Function
- Perl | abs() function
- Perl | atan2() Function
- Perl | splice() - The Versatile Function
- Perl | delete() Function
- Perl | defined() Function
- Perl | each() Function
- Perl | index() Function
- Perl | int() function
- Perl | join() Function
- Perl | keys() Function
- Perl | lc() Function for Lower Case Conversion
- Perl | lcfirst() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.