Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Cut the last invisible spaces from the words

Reply
Thread Tools

Cut the last invisible spaces from the words

 
 
Dave
Guest
Posts: n/a
 
      11-25-2004
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



 
Reply With Quote
 
 
 
 
Dave
Guest
Posts: n/a
 
      11-25-2004
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];
}
:



"Dave" <(E-Mail Removed)> wrote in message
news:co5ieh$728$(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      11-26-2004
Dave <(E-Mail Removed)> wrote:

> 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?


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[CSS] how can I show spaces as spaces? Tomasz Chmielewski HTML 21 09-10-2009 06:43 PM
Re: How to trim a String trailing spaces, but not leading spaces? Roedy Green Java 3 09-14-2008 02:10 AM
Re: How to trim a String trailing spaces, but not leading spaces? John B. Matthews Java 4 09-12-2008 05:28 AM
Making 1 control invisible while showing another in the exact location of the invisible one Andy B ASP .Net 5 05-29-2008 03:08 AM
Invisible - Succinic acid : (AMBER ACID) Invisible krithika.143@gmail.com C++ 0 04-14-2008 06:59 PM



Advertisments