Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

wwwxxxx.jpeg, xxxxdup, WWWXXX..APC site:board.issociate.de, WWWXXXAPC, WWWXXX .CMD, Wwwwxxx reemine, WWWXXX.VCBA, WWWXXX.VCBA, TheboL.wwwxxxxx, WWWXXXAPC

Links

XODOX
Impressum

#1: s replace p modifier

Posted on 2008-04-15 01:13:05 by Lore Leunoeg

Hello

I'd like to encapsulate each number in a textfile with dollar-signs ($). I
thougt to replace each number by a $-sign followed by the pattern matched
number itself and another $-sign.

How can I get the exact pattern which was replaced by
s/PATTERN/PREPLACEMENT/modifier?
In the perl docs I read that the p preserve modifier would save the replaced
pattern in a variable $<^MATCH>. But the p modifier isn't known by my perl
installation (vers5.8).

Does anybody know another way to solve the encapsulation problem? Or does
anyone can give me a hint why the p modifier isn't known?

Thank you
Sincerely
Lore

Report this message

#2: Re: s replace p modifier

Posted on 2008-04-15 01:13:09 by 1usa

"Lore Leunoeg" <loreleunoeg@gmx.net> wrote in
news:fu0o1b$vt0$1@news01.versatel.de:

> I'd like to encapsulate each number in a textfile with
> dollar-signs ($). I thougt to replace each number by a $-sign
> followed by the pattern matched number itself and another $-sign.

OK, stop here. The rest of your post is extremely confusing to me
because I cannot see why you would need the p modifier.

#!/usr/bin/perl

use strict;
use warnings;

while ( <DATA> ) {
s/(\d+)/\$$1\$/g;
print "$_\n";
}

__DATA__
a 1 2 3
b 2 3 4
c 3 4 g
d 4 h i
e 5 9 a

> Does anybody know another way to solve the encapsulation problem?

I don't know what *the* encapsulation problem is.

> Or does anyone can give me a hint why the p modifier isn't known?

Because you don't have perl 5.10.

Sinan

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Report this message

#3: Re: s replace p modifier

Posted on 2008-04-15 02:44:12 by Tad J McClellan

Lore Leunoeg <loreleunoeg@gmx.net> wrote:
> Hello
>
> I'd like to encapsulate each number in a textfile with dollar-signs ($). I
> thougt to replace each number by a $-sign followed by the pattern matched
> number itself and another $-sign.


That's a very good thought.


> How can I get the exact pattern which was replaced by
> s/PATTERN/PREPLACEMENT/modifier?


[ Please copy/paste code rather than (attempt to) retype it. ]


By enclosing the PATTERN in parenthesis and using the $1 variable
in the REPLACEMENT part.


> In the perl docs I read that the p preserve modifier would save the replaced
> pattern in a variable $<^MATCH>. But the p modifier isn't known by my perl
> installation (vers5.8).


You should not read random Perl docs from the web.

You should read the Perl docs that *came with* your perl distribution.

They are already on your disk somewhere. Find out where.


> Does anybody know another way to solve the encapsulation problem? Or does
> anyone can give me a hint why the p modifier isn't known?


You were reading docs that did not apply to the software
that you currently have available.

That can never happen if you read the docs that came with the
software that you currently have available.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Report this message

#4: Re: s replace p modifier

Posted on 2008-04-15 05:24:51 by szr

Tad J McClellan wrote:
> Lore Leunoeg <loreleunoeg@gmx.net> wrote:
>> Hello
>>
>> I'd like to encapsulate each number in a textfile with dollar-signs
>> ($). I thougt to replace each number by a $-sign followed by the
>> pattern matched number itself and another $-sign.
>
>
> That's a very good thought.
>
>
>> How can I get the exact pattern which was replaced by
>> s/PATTERN/PREPLACEMENT/modifier?
>
>
> [ Please copy/paste code rather than (attempt to) retype it. ]
>
>
> By enclosing the PATTERN in parenthesis and using the $1 variable
> in the REPLACEMENT part.
>
>
>> In the perl docs I read that the p preserve modifier would save the
>> replaced pattern in a variable $<^MATCH>. But the p modifier isn't
>> known by my perl installation (vers5.8).
>
>
> You should not read random Perl docs from the web.
>
> You should read the Perl docs that *came with* your perl distribution.
>
> They are already on your disk somewhere. Find out where.
>
>
>> Does anybody know another way to solve the encapsulation problem? Or
>> does anyone can give me a hint why the p modifier isn't known?
>
>
> You were reading docs that did not apply to the software
> that you currently have available.
>
> That can never happen if you read the docs that came with the
> software that you currently have available.

True enough, though it is possible to read the wrong documents if one's
system has multiple installs (for instance, one that came bundled with
your system and one and compiled by hand afterwards), and also some
people use systems they did not set up (i.e., in a work place
environment.)

If in doubt, invoke perldoc by absolute path.

For example, I my own system, I have 5.10.0 and 5.8.8 installed in
/usr/local/ perl5.8.8 and perl5.10.0 and have symlinked binaries from
each (perl, perldoc, etc) as /usr/local/bin perl5.8.8 and perldoc5.8.8
and similar for 5.10.0, respectively, that way I am always sure of which
one I am invoking (though I use 5.10.0 as my primary Perl now... perl
and perldoc are too symlinked to 5.10.0's binaries.)

--
szr

Report this message

#5: Re: s replace p modifier

Posted on 2008-04-15 10:53:14 by Abigail

_
Lore Leunoeg (loreleunoeg@gmx.net) wrote on VCCCXL September MCMXCIII in
<URL:news:fu0o1b$vt0$1@news01.versatel.de>:
-- Hello
--
-- I'd like to encapsulate each number in a textfile with dollar-signs ($). I
-- thougt to replace each number by a $-sign followed by the pattern matched
-- number itself and another $-sign.
--
-- How can I get the exact pattern which was replaced by
-- s/PATTERN/PREPLACEMENT/modifier?
-- In the perl docs I read that the p preserve modifier would save the replaced
-- pattern in a variable $<^MATCH>. But the p modifier isn't known by my perl
-- installation (vers5.8).

It really would help if you used the documentation that comes with your Perl.
None of the 5.8 versions will document the /p modifier. It wasn't documented
until perl 5.10, which does know the /p modifier.

But it doesn't say $<^MATCH>. The variable is called ${^MATCH}.

-- Does anybody know another way to solve the encapsulation problem? Or does
-- anyone can give me a hint why the p modifier isn't known?

No need for /p and ${^MATCH}. The following ought to do (not tested):

s/([0-9]+)/\$$1\$/g;


Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC ;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi

Report this message