Cut the last invisible spaces from the words

D

Dave

Sorry to bother you, guys

I have a problem here that :

There is a Txt file formateted like

Apple (2 spaces after Apple, then \n)
Orange (4 spaces after Apple, then \n)
...................

When I use grep, and store the row value to $A. It actually contains some
invisible spaces which failed in the my database query.
Is there any good way to get rid of these spaces?

Thanks
 
D

Dave

I found one sub routine which can solve this problem.

$many = trim($many);

sub trim {
my @out = @_;
for (@out) {
s/^\s+//;
s/\s+$//;
}
return wantarray ? @out : $out[0];
}
:
 
T

Tad McClellan

Dave said:
Sorry to bother you, guys


Apologizing for asking a Frequently Asked Question does not make
it OK to ask a Frequently Asked Question.

You are expected to check the Perl FAQ *before* you post to the
Perl newsgroup.

Apple (2 spaces after Apple, then \n)

When I use grep,


Why are you using grep(1) when you have Perl?

Perl can do what grep(1) does, there is no need to shell out.

Is there any good way to get rid of these spaces?


perldoc -q space

How do I strip blank space from the beginning/end of a string?
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top