Process string.

Discussion in 'Perl' started by Hon Seng Phuah, Feb 13, 2004.

  1. Hi all,

    I am new to perl language and need someone to help me.

    If I have three sentenses.

    Too good to be true.
    It is raining today.
    They wanted the meeting to be on Thursday.

    If I want to get the second of word of each sentense. How shall I
    write a function in perl language?

    Thanks and have a good day.
    -HS Phuah
    Hon Seng Phuah, Feb 13, 2004
    #1
    1. Advertising

  2. Hon Seng Phuah wrote:
    > If I have three sentenses.
    >
    > Too good to be true.
    > It is raining today.
    > They wanted the meeting to be on Thursday.
    >
    > If I want to get the second of word of each sentense. How shall I
    > write a function in perl language?


    http://learn.perl.org/

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 13, 2004
    #2
    1. Advertising

  3. Gunnar Hjalmarsson <> wrote in message news:<S31Xb.48908$>...
    > Hon Seng Phuah wrote:
    > > If I have three sentenses.
    > >
    > > Too good to be true.
    > > It is raining today.
    > > They wanted the meeting to be on Thursday.
    > >
    > > If I want to get the second of word of each sentense. How shall I
    > > write a function in perl language?

    >
    > http://learn.perl.org/


    Thanks for the url link. The url link examples are too simple and do
    not help me to solve above problem. If you have an example to extract
    the second word in each sentenses by using for or while, could you
    please write your function and post it to this newsgroup.

    Thanks and have a good day.
    -HS Phuah
    Hon Seng Phuah, Feb 13, 2004
    #3
  4. Hon Seng Phuah wrote:
    > Gunnar Hjalmarsson <> wrote in message
    > news:<S31Xb.48908$>...
    >> Hon Seng Phuah wrote:
    >>> If I have three sentenses.
    >>>
    >>> Too good to be true.
    >>> It is raining today.
    >>> They wanted the meeting to be on Thursday.
    >>>
    >>> If I want to get the second of word of each sentense. How shall I
    >>> write a function in perl language?

    >
    > The [...] examples are too simple and do
    > not help me to solve above problem. If you have an example to extract
    > the second word in each sentenses by using for or while,


    You don't use a loop for that. Have a look at the split() function.
    Depending upon how you define a word all you need to do is probably
    splitting the string at space characters and then just take the second
    element.

    (undef, $word) = split / /, $sentence;

    > could you
    > please write your function and post it to this newsgroup.


    Really, you are thinking way to complicated. Nobody would write a function
    for that.

    jue
    Jürgen Exner, Feb 14, 2004
    #4
    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. Rithesh Pai
    Replies:
    1
    Views:
    5,596
  2. walala
    Replies:
    3
    Views:
    736
    Allan Herriman
    Sep 9, 2003
  3. Earl Eiland
    Replies:
    3
    Views:
    525
    Peter Hansen
    May 16, 2005
  4. Trent Mick
    Replies:
    0
    Views:
    479
    Trent Mick
    May 16, 2005
  5. EJS
    Replies:
    0
    Views:
    309
Loading...

Share This Page