What is the difference between chop & chomp functions in perl?

Answer Posted / pallavi

Chop function removes the last character of any specified
string or variable and returns the chopped data.

Ex: $a="abcdefghijkla";
$b= chop($a);
print $a;

Output - abcdefghijkl

Where as chomp removes all the new line at the end of any
specified string or variable and returns nothing.

Is This Answer Correct ?    15 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the two ways to get private values inside a subroutine?

614


How to add elements in a hash in perl?

679


Explain chomp, chop, cpan, tk.

711


Explain subroutine?

688


Explain regular expression in perl?

725


How does polymorphism work in perl?

689


What is q (single q) operator in perl?

749


Explain lexical variables.

713


You want to read command-line arguements with perl. How would you do that?

679


How can you replace the characters from a string and save the number of replacements?

697


If EXPR is an arbitrary expression, what is the difference between $Foo::{EXPR} and *{"Foo::".EXPR}?

706


What is Perl?

764


What is the difference between die and exit in perl?

757


What's the difference between /^Foo/s and /^Foo/?

775


Explain different types of perl operators.

714