What is the use of s { } { }

Discussion in 'Perl Misc' started by Subra, Dec 4, 2007.

  1. Subra

    Subra Guest

    Hi,

    Can any one tell me, whats does the "s { } { }" operator used for in
    the below code ?

    next unless s{^(\s*\w+\s+$stat_pid\s+(\d+)\s+)\d+\s+.*$pattern$}
    {$1};

    this is used to search for a existence of the process through ps -ef.

    Best Regards,
    Subra...
     
    Subra, Dec 4, 2007
    #1
    1. Advertising

  2. Subra

    Guest

    On Dec 4, 3:16 pm, Subra <> wrote:
    > Can any one tell me, whats does the "s { } { }" operator used for


    see perldoc perlop, section "Regexp Quote-Like Operators", s/PATTERN/
    REPLACEMENT/msixpogce

    > in the below code ?
    >
    > next unless s{^(\s*\w+\s+$stat_pid\s+(\d+)\s+)\d+\s+.*$pattern$}
    > {$1};


    see perldoc perlre
     
    , Dec 4, 2007
    #2
    1. Advertising

  3. Subra

    Guest

    Subra <> wrote:
    > Hi,
    >
    > Can any one tell me, whats does the "s { } { }" operator used for in
    > the below code ?


    It is the same thing as the much more common "s///", just with different
    delimiters.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
     
    , Dec 4, 2007
    #3
  4. Subra wrote:
    > Can any one tell me, whats does the "s { } { }" operator used for in
    > the below code ?
    >
    > next unless s{^(\s*\w+\s+$stat_pid\s+(\d+)\s+)\d+\s+.*$pattern$}
    > {$1};


    It is substitution whatever was matched by the RE
    ^(\s*\w+\s+$stat_pid\s+(\d+)\s+)\d+\s+.*$pattern$
    with the actual text that was matched by
    (\s*\w+\s+$stat_pid\s+(\d+)\s+)

    In short: it is removing some trailing text.

    jue
     
    Jürgen Exner, Dec 4, 2007
    #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. Replies:
    6
    Views:
    7,124
  2. M K
    Replies:
    11
    Views:
    7,058
    woods_jemmy
    Apr 9, 2008
  3. Simon
    Replies:
    1
    Views:
    451
    Henri
    Nov 9, 2004
  4. =?Utf-8?B?S2hhaXJvbA==?=
    Replies:
    0
    Views:
    359
    =?Utf-8?B?S2hhaXJvbA==?=
    Dec 10, 2004
  5. =?Utf-8?B?SmVmZiBLZXNpbmdlcg==?=

    Common Web functions dll (Used to use MTS, what do I use in .NET

    =?Utf-8?B?SmVmZiBLZXNpbmdlcg==?=, Dec 28, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    464
    charlie
    Apr 30, 2005
Loading...

Share This Page