From: Phred Phungus on
J�rgen Exner wrote:
> Phred Phungus <Phred(a)example.invalid> wrote:
>> PerlFAQ Server wrote:
>>> This is an excerpt from the latest version perlfaq6.pod, which
>>> comes with the standard Perl distribution. These postings aim to
>>> reduce the number of repeated questions as well as allow the community
>>> to review and update the answers. The latest version of the complete
>>> perlfaq is at http://faq.perl.org .
>>>
>>> --------------------------------------------------------------------
>>>
>>> 6.9: How can I quote a variable to use in a regex?
>>>
>>> The Perl parser will expand $variable and @variable references in
>>> regular expressions unless the delimiter is a single quote. Remember,
>>> too, that the right-hand side of a "s///" substitution is considered a
>>> double-quoted string (see perlop for more details). Remember also that
>>> any regex special characters will be acted on unless you precede the
>>> substitution with \Q. Here's an example:
>>>
>>> $string = "Placido P. Octopus";
>>> $regex = "P.";
>>>
>>> $string =~ s/$regex/Polyp/;
>>> # $string is now "Polypacido P. Octopus"
>>>
>>> Because "." is special in regular expressions, and can match any single
>>> character, the regex "P." here has matched the <Pl> in the original
>>> string.
>>>
>> Am I then correct that a period is not a character?
>
> ???
> How did you come to that conclusion?

Because the regex would then match the middle initial and the string
would be "Polypacido Polyp Octopus".
--
fred
From: J�rgen Exner on
Phred Phungus <Phred(a)example.invalid> wrote:
>J�rgen Exner wrote:
>> Phred Phungus <Phred(a)example.invalid> wrote:
>>> PerlFAQ Server wrote:
>>>> $string = "Placido P. Octopus";
>>>> $regex = "P.";
>>>>
>>>> $string =~ s/$regex/Polyp/;
>>>> # $string is now "Polypacido P. Octopus"
>>>>
>>>> Because "." is special in regular expressions, and can match any single
>>>> character, the regex "P." here has matched the <Pl> in the original
>>>> string.
>>>>
>>> Am I then correct that a period is not a character?
>>
>> How did you come to that conclusion?
>
>Because the regex would then match the middle initial and the string
>would be "Polypacido Polyp Octopus".

No, it wouldn't because there is no /g modifier in the s///-operation.

jue
From: Uri Guttman on
>>>>> "R" == Ruud <rvtol+usenet(a)xs4all.nl> writes:

R> Uri Guttman wrote:
>> Ruud:
>>> Uri:

>>>> i generally use \. but [.] is ok imo.
>>>
>>> The performance loss was lifted in 5.10, IIRC.
>>
>> i wasn't concerned with performance but style. the hex version of . is
>> what i never want to see. i don't need to look up hex codes to see you
>> are trying to match a literal . :)

R> Don't shoot the messenger. :)

R> I don't understand why you reply on content that was no longer there.
R> And you are repeating what you expressed before.

R> I also don't understand why you assume that I addressed any concern of
R> yours.
R> I merely stated a "fact". (but it could be in 5.10.1 or later too)

ok, i will admit i am lost as what is going on in this thread anymore
and give up on it. no loss.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Ilya Zakharevich on
On 2010-03-29, Uri Guttman <uri(a)StemSystems.com> wrote:
>>>>>> "R" == Ruud <rvtol+usenet(a)xs4all.nl> writes:
>
> R> Steve M wrote:
> >> To access a literal '.' you need to backslash it
>
> R> Or quotemeta it, or put it in a character class, or mention it as
> R> \x2E, etc., etc.
>
> i would never encode a literal . as \2e. too obscure and what about
> unicode (not that i am anything but an ascii bigot! :)?

What about unicode?

Puzzled,
Ilya
From: Ilya Zakharevich on
On 2010-03-29, Uri Guttman <uri(a)StemSystems.com> wrote:
> i wasn't concerned with performance but style. the hex version of . is
> what i never want to see. i don't need to look up hex codes to see you
> are trying to match a literal . :)

May be "needed" (in the sense: more readable than alternatives, and
more shell-neutral) in a one-liner to protect "pesky" shell
meta-characters (such as % in DOSISH shells, and ! in tcsh)...

Yours,
Ilya