In Perl, the basic difference between the keywords 'chop' and 'chomp' is as follows:
Chop is used to literally chop the last character of a string. It simply deletes the last character.
Eg:
chop garlic;
The output will be garli with 'c' getting chopped off :)
On the other hand, Chomp is used to delete the endline character "\n";
Eg:
$var = "garlic\n";
chomp $var;
The resultant value of $var will be the same string garlic, but with only the newline character getting deleted.
Chop is used to literally chop the last character of a string. It simply deletes the last character.
Eg:
chop garlic;
The output will be garli with 'c' getting chopped off :)
On the other hand, Chomp is used to delete the endline character "\n";
Eg:
$var = "garlic\n";
chomp $var;
The resultant value of $var will be the same string garlic, but with only the newline character getting deleted.
No comments:
Post a Comment