Cut the last invisible spaces from the words

Discussion in 'Perl Misc' started by Dave, Nov 25, 2004.

  1. Dave

    Dave Guest

    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
    Dave, Nov 25, 2004
    #1
    1. Advertising

  2. Dave

    Dave Guest

    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" <> wrote in message
    news:co5ieh$728$...
    > 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
    >
    >
    >
    Dave, Nov 25, 2004
    #2
    1. Advertising

  3. Dave <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 26, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Diego F.

    Printint datagrid: last row cut

    Diego F., Jun 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    378
    Diego F.
    Jun 8, 2005
  2. Peter Strøiman
    Replies:
    1
    Views:
    2,085
    Peter Strøiman
    Aug 23, 2005
  3. Richard Heathfield
    Replies:
    7
    Views:
    361
    Barry Schwarz
    Oct 5, 2003
  4. utab

    Words Words

    utab, Feb 16, 2006, in forum: C++
    Replies:
    6
    Views:
    420
    Daniel T.
    Feb 16, 2006
  5. Andy B
    Replies:
    5
    Views:
    590
    Andy B
    May 29, 2008
Loading...

Share This Page