What is the use of s { } { }

What is the use of s { } { }

am 04.12.2007 15:16:14 von Subra

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

Re: What is the use of s { } { }

am 04.12.2007 15:41:44 von dilbert1999

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

Re: What is the use of s { } { }

am 04.12.2007 16:54:03 von xhoster

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.

Re: What is the use of s { } { }

am 04.12.2007 17:58:08 von jurgenex

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

Re: What is the use of s { } { }

am 05.12.2007 04:44:53 von Petr Vileta

Subra wrote:
> 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};
>

In RegExp you can use almost any delimiters. Most used are
s/PATERN/REPLACEMENT/;
but when I want to use / somewhere in the regexp then I tend to write it as
s#some/patern#REPLACEMENT#;
This allow me to avoid escaping /. Use basic syntax for example above this
will be write as
s/some\/patern/REPLACEMENT/;

You can use parenthesis too but in this case you must use left and right to
pair these.

--
Petr
Skype: callto://fidokomik
Na mail uvedeny v headeru zpravy nema cenu nic posilat, konci to v PR*
:-)

Odpovidejte na petr na practisoft cz


Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)

Please reply to