Friday, January 27, 2017

difference between Chop and Chomp Chop: 1) Chop removes any last character from string or line. 2) This removes last character of the string and return that character $str = "How Are You"; chop($str); print $str; #output 'How Are Yo' $str = "How Are You"; $newStr = chop($str); print $newStr; #output would be 'u' -------------------------- Chomp: 1) this removes any special character at the end of the line or string 2) It removes characters at the end of strings corresponding to the $INPUT_LINE_SEPARATOR ($/) 3) It return number of characters removed $str = "How Are You\n"; chomp($str); print $str; #output would be How Are You', it removed special newline char '\n' $a = "How Are You\n"; $b = chomp($a); print $b; #it would be returning 1, it did removed one character something for sure