|
Posted by szr on April 14, 2008, 11:24 pm
Please log in for more thread options Tad J McClellan 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
|