469,898 Members | 1,707 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Question on Chomp

I have this piece of code:

$/ = ' ';
$test = "abc ";
chomp $test;
print $test;

which prints spaces at the end of the line. Shouldn't chomp strip the spaces
off the end of my scalar $test?

-Matt
Jul 19 '05 #1
2 5150
Matt Taylor wrote:
I have this piece of code:

$/ = ' ';
$test = "abc ";
chomp $test;
print $test;

which prints spaces at the end of the line. Shouldn't chomp strip the spaces
off the end of my scalar $test?


try:

$/ = ' ';
$test = "abc ";
print "$test<\n";
chomp $test;
print "$test<\n";

D:\Snippets>chomp.pl
abc <
abc <

stripping can be done with:

$test =~ s/\s*$//;

ie. remove zero or more (*) white space (\s) form the end ($).

--
Kind regards, prachtige ideeen
John aan het einde van een dal
stromen dagelijks
http://johnbokma.com/ gedachtenwaterval

Jul 19 '05 #2
"John Bokma" <po********@castleamber.com> wrote in message
news:10***************@halkan.kabelfoon.nl...
Matt Taylor wrote:
I have this piece of code:

$/ = ' ';
$test = "abc ";
chomp $test;
print $test;

which prints spaces at the end of the line. Shouldn't chomp strip the spaces off the end of my scalar $test?


try:

$/ = ' ';
$test = "abc ";
print "$test<\n";
chomp $test;
print "$test<\n";

D:\Snippets>chomp.pl
abc <
abc <

stripping can be done with:

$test =~ s/\s*$//;

ie. remove zero or more (*) white space (\s) form the end ($).

--
Kind regards, prachtige ideeen
John aan het einde van een dal
stromen dagelijks
http://johnbokma.com/ gedachtenwaterval


Ah. Reading through perlfunc it sounded like chomp ate every trailing
string. I've never really questioned how to use it since I've used it
exclusively to chomp the newlines off of file input.

Thanks for the help.

-Matt
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Fernando Armenta | last post: by
reply views Thread by Aaron Powell | last post: by
35 posts views Thread by lnatz | last post: by
3 posts views Thread by adriaan | last post: by
3 posts views Thread by Iron Blood | last post: by
6 posts views Thread by Iron Blood | last post: by
4 posts views Thread by g0uki | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.