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

Answers were Sorted based on User's Feedback



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

Answer / thangaraju

chop is used remove last character,chomp function removes
only line endings.

Is This Answer Correct ?    80 Yes 15 No

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

Answer / devinder kumar

chop will indiscriminately remove (and return) the last
character passed to it, while chomp will only remove the
end of record marker (generally, "\n"), and return the
number of characters so removed.

Is This Answer Correct ?    40 Yes 4 No

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

Answer / nagaraju kancherla

chop() removes the last character from a scalar value.

chomp() checks whether the last characters of a string or
list of strings match the input line separator defined by
the $/ system variable. If they do, chomp removes them.


Is This Answer Correct ?    25 Yes 5 No

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

Answer / 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

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

Answer / deepesh

chop() is used to remove last character where chomp() is
only remove new line if its existing or white space.

Is This Answer Correct ?    8 Yes 0 No

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

Answer / mass

Chop removes the last character of string completely and returns that last character. While chomp removes the last character if it is new line.

Is This Answer Correct ?    5 Yes 0 No

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

Answer / wicked_sunny

Chop and Chomp are two very similar functions. Both of them
are used to delete symbols from the tail of the given
string. While both work with string and list parameters,
Chop deletes any ending symbol Chomp deletes only specified
substring from the end. If you pass list to any of these
two, all list elements will get processed and the return
value would be the result of last operation.

Is This Answer Correct ?    22 Yes 20 No

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

Answer / ramya

chop removes the last character and returns the character
chopped
Chomp removes any trailing string that corresponds to the
current value of $/ and returns number of characters removed

Is This Answer Correct ?    11 Yes 10 No

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

Answer / shaheed

If there is new line character at the end of string, chop()
and chomp() both will remove that new line character.

Else if there is no new line character at the end of string
then chop() will remove last character from the string
while chomp() keeps the string unchanged.

Is This Answer Correct ?    0 Yes 2 No

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

Answer / preethi

chop removes last character of the given string whereas
chomp removes the whitespace along with the character at the
end

chop-------> Perl----> Per
chomp------> Perl Program ----> Perl

Is This Answer Correct ?    4 Yes 15 No

Post New Answer

More CGI Perl Interview Questions

Mention the difference between die and exit in Perl?

0 Answers  


How to read multi lines from a file in perl?

0 Answers  


What is the use of –w?

0 Answers  


write a perl script to find whether a given line of text is starting and ending with same word or not ???

2 Answers   CSS,


What is the use of "stderr()"?

0 Answers  






What is the use of -t?

0 Answers  


What are the various file operations in perl. Explain with example.

0 Answers  


What are the characteristics of a project that is well suited to Perl?

1 Answers  


How to get help for perl?

0 Answers  


How many types of primary data structures in Perl and what do they mean?

0 Answers  


What are numeric operators in perl?

0 Answers  


Try pattern matching for the following: 1) 10.111.23.11 2) /root/abc/cde/fgg/ac.xml --> Get file name without extention. 3) /root/abc/ac.xml/fgg/ac.xml --> Get file name without extention. 4) What does "DIE" meant in PERL? 5) chomp 6) "This is saturday" --> Print the weekday number. 7) 11-2-2009 --> Print the name of the month. 8) Reverse the string without using func in C.

2 Answers  


Categories