develooper Front page | perl.perl5.porters | Postings from October 2016

Re: [perl #129277] [PATCH] addition to perlrecharclass about '$' as"special"

Thread Next
From:
Kevin Goess
Date:
October 18, 2016 17:12
Subject:
Re: [perl #129277] [PATCH] addition to perlrecharclass about '$' as"special"
Message ID:
CAJMdQC3bXAg_VMWmQHqfHtNg6kkcyJ6tgJ2XqzLuyPd9XJC+jg@mail.gmail.com
Instead of "beware that" I might say "be aware that", but otherwise it
looks good to me.

On Mon, Oct 17, 2016 at 7:44 PM, Karl Williamson via RT <
perlbug-followup@perl.org> wrote:

> On Thu Sep 15 16:13:23 2016, abigail@abigail.be wrote:
> > On Thu, Sep 15, 2016 at 11:34:02AM -0700, Kevin Goess wrote:
> > > # New Ticket Created by  Kevin Goess
> > > # Please include the string:  [perl #129277]
> > > # in the subject line of all future correspondence about this issue.
> > > # <URL: https://rt.perl.org/Ticket/Display.html?id=129277 >
> > >
> > >
> > > This is a bug report for perl from cpan@goess.org,
> > > generated with the help of perlbug 1.40 running under perl 5.25.5.
> > >
> > >
> > > -----------------------------------------------------------------
> > > [Please describe your issue here]
> > >
> > > I'm suggesting a documentation change. perlrecharclass says "Most
> > > characters
> > > that are meta characters in regular expressions...lose their special
> > > meaning
> > > and can be used inside a character class without the need to escape
> > > them" and
> > > goes on to list the ones that do need to be escaped. It does *not*
> > > list a '$'.
> > > But this will not match a dollar sign or a comma:
> > >
> > > [$,]
> >
> >
> > But it does:
> >
> > $ perl -wE 'say q{$} =~ q{[$,]}'
> > 1
> > $
> >
> > >
> > > and it would be good advice to point out that a '$' is as special
> > > inside a
> > > character class as it is anywhere else in a regular expression.
> > >
> >
> >
> > Now, if you use delimiters which allow for interpolation of variables,
> > said interpolation will happen -- but it will happen before perl even
> > knows there is a character class.
> >
> >
> >
> > Abigail
>
> How about the attached patch instead?
>
> --
> Karl Williamson
>
> From a6b63f4e4781c3ae0a4dc1e4ae0eedd98bb7e781 Mon Sep 17 00:00:00 2001
> From: Karl Williamson <khw@cpan.org>
> Date: Thu, 15 Sep 2016 21:52:44 -0600
> Subject: [PATCH] alternate patch for 129277
>
> ---
>  pod/perlrecharclass.pod | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/pod/perlrecharclass.pod b/pod/perlrecharclass.pod
> index 89f4a7e..51ad3db 100644
> --- a/pod/perlrecharclass.pod
> +++ b/pod/perlrecharclass.pod
> @@ -512,7 +512,13 @@ is, characters that carry a special meaning like
> C<.>, C<*>, or C<(>) lose
>  their special meaning and can be used inside a character class without
>  the need to escape them. For instance, C<[()]> matches either an opening
>  parenthesis, or a closing parenthesis, and the parens inside the character
> -class don't group or capture.
> +class don't group or capture.  Beware that, unless the pattern is
> +enclosed in single-quotes, variable interpolation will take place before
> +the bracketed class is parsed:
> +
> + $, = "\t| ";
> + $a =~ m'[$,]';        # single-quotish: matches '$' or ','
> + $a =~ m/[$,]/;        # double-quotish: matches "\t", "|", or " "
>
>  Characters that may carry a special meaning inside a character class are:
>  C<\>, C<^>, C<->, C<[> and C<]>, and are discussed below. They can be
> --
> 2.7.4
>
>
>

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About