Multiple choice technology web technology

in perl , whats the difference between chomp and chop command

  1. deletes first and last characters respectively

  2. clears newline character if present and clears last character(anything) respectively

  3. deletes last and first characters respectively

  4. clears last character(anything) and clears newline character if present respectively

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Perl, chomp() removes the trailing newline character (usually from input) only if present, leaving other characters intact. chop() always removes and returns the last character regardless of what it is, which can be problematic if used on strings without a trailing newline. Chomp is the safer choice for cleaning input.