how to add a space after first word ina s entence

Discussion in 'Perl Misc' started by sudip05@mailcity.com, Jul 18, 2006.

  1. Guest

    Hi All,
    I am having a senmtence. After the first word, I have to add a
    single space there...can anybody gimme a coincise code. I tried
    breaking up the sentence, but it removes the spaces also which I dont
    want.

    Code snippet
    first line: selects lineString example: "int *ptr ptr is a pointer"

    if($lineString =~ m/(\s*\@param\s*)\*(.*\r*\n*)/)
    {
    $lineString = $1.$2; /*$1 is "int " $2 is "ptr is a pointer"
    */

    I have to produce output like "int ptr(then 1 single space) is a
    pointer". So I have to manipulate $2 in such a way that after first
    word in $2, there goes another extra space.



    Can anybody help.

    Thanks,

    sudip
    , Jul 18, 2006
    #1
    1. Advertising

  2. wrote:

    > I am having a senmtence. After the first word, I have to add a
    > single space there...can anybody gimme a coincise code.


    s/(\w+)/$1 /;

    Somehow, I suspect that's not what you meant.

    > first line: selects lineString example: "int *ptr ptr is a pointer"
    >
    > if($lineString =~ m/(\s*\@param\s*)\*(.*\r*\n*)/)
    > {
    > $lineString = $1.$2; /*$1 is "int " $2 is "ptr is a pointer"
    > */


    That is not valid Perl - it will not compile.

    There was no '@params' in your example input so your pattern will not
    match.

    That yo you think the pattern /(.*\r*\n*)/ matches?

    > I have to produce output like "int ptr(then 1 single space) is a
    > pointer". So I have to manipulate $2 in such a way that after first
    > word in $2, there goes another extra space.


    The dolar-digit variables are readonly. You need to copy the string to
    an ordinary scalar variable then manipulate it in the usual way. (e.g.
    with s///).

    Please produce minimal but complete code to illustrate your quesrtion.

    > Can anybody help.


    Only if you describe what you want to achive in term that other people
    could possibly understant.
    Brian McCauley, Jul 18, 2006
    #2
    1. Advertising

  3. Guest

    Hi Brian,
    I am sorry..yes, u r very true...the code that I gave wont
    work, but you gave the corect solution(inserting a space after the
    first word in a sntence)...thanks a lot..... :)

    ~Ciao


    Brian McCauley wrote:
    > wrote:
    >
    > > I am having a senmtence. After the first word, I have to add a
    > > single space there...can anybody gimme a coincise code.

    >
    > s/(\w+)/$1 /;
    >
    > Somehow, I suspect that's not what you meant.
    >
    > > first line: selects lineString example: "int *ptr ptr is a pointer"
    > >
    > > if($lineString =~ m/(\s*\@param\s*)\*(.*\r*\n*)/)
    > > {
    > > $lineString = $1.$2; /*$1 is "int " $2 is "ptr is a pointer"
    > > */

    >
    > That is not valid Perl - it will not compile.
    >
    > There was no '@params' in your example input so your pattern will not
    > match.
    >
    > That yo you think the pattern /(.*\r*\n*)/ matches?
    >
    > > I have to produce output like "int ptr(then 1 single space) is a
    > > pointer". So I have to manipulate $2 in such a way that after first
    > > word in $2, there goes another extra space.

    >
    > The dolar-digit variables are readonly. You need to copy the string to
    > an ordinary scalar variable then manipulate it in the usual way. (e.g.
    > with s///).
    >
    > Please produce minimal but complete code to illustrate your quesrtion.
    >
    > > Can anybody help.

    >
    > Only if you describe what you want to achive in term that other people
    > could possibly understant.
    , Jul 18, 2006
    #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. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,883
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,643
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    1,005
    Steve Lamb
    Oct 23, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    716
    Michael Hudson
    Oct 24, 2003
  5. Kev Jackson
    Replies:
    12
    Views:
    176
    Adam Sanderson
    Jan 12, 2006
Loading...

Share This Page