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

How we can navigate the xml documents?

535


How to read from a pipeline with Perl

547


What is perl programming?

557


Comment on the scope of variables in perl.

525


What does last statement do in perl?

527






What interface used in PERL to connect to database? How do you connect to database in Perl?

534


What are scalars?

547


Explain the use of 'my' keyword in perl?

559


Explain what is STDIN, STDOUT and STDERR?

541


What is chomp() operator/function?

565


How will you open a file in read-only mode in perl?

509


How to copy a file in perl?

512


Explain goto name?

522


what is the function that is used to identify how many characters are there in a string?

540


Explain 'grep' function.

539