Don't ask to ask, just ask | |
PerlMonks |
remember.. this with a little bit of usefulness chop() can be the same as chomp()#chomp() EXAMPLES $a = "abcdefghij"; chomp($a); print $a; #would return exact string... nothing to remove $a = "abcdefghij\n"; chomp($a); print $a; #would return 'abcdefghij', removed newline $a = "abcdefghij\n"; $b = chomp($a); print $b; #would return 1, it did remove something for sure #chop() EXAMPLES $a = "abcdefghij"; chop($a); print $a; #this would return 'abcdefghi' $a = "abcdefghij"; $b = chop($a); print $b; #this would return 'j'
most of the time, you'll want to chomp(), but you might want to use chop() with regexes for the same output$a = "abcdefghij\n"; if ($a =~ /\n$/) { chop $a; } #this could also be \r\n if on windows p +latform
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: chop() and chomp()
by davorg (Chancellor) on Jan 02, 2002 at 15:39 UTC | |
Re: chop() and chomp()
by Juerd (Abbot) on Jan 01, 2002 at 22:00 UTC | |
by Parham (Friar) on Jan 03, 2002 at 05:51 UTC | |
by Anonymous Monk on Mar 15, 2006 at 02:50 UTC | |
Re: chop() and chomp()
by SamCG (Hermit) on Mar 15, 2006 at 18:09 UTC | |
by TGI (Parson) on May 25, 2007 at 22:18 UTC | |
Re: chop() and chomp()
by pikablu (Initiate) on May 25, 2007 at 20:39 UTC | |
by Anonymous Monk on Jan 30, 2010 at 09:49 UTC |