Question on Chomp

M

Matt Taylor

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
 
J

John Bokma

Matt said:
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 ($).
 
M

Matt Taylor

John Bokma said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top