develooper Front page | perl.perl5.porters | Postings from February 2015

[perl #123820] documentation error in perlrecharclass

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
February 13, 2015 23:58
Subject:
[perl #123820] documentation error in perlrecharclass
Message ID:
rt-4.0.18-31281-1423871886-1831.123820-15-0@perl.org
On Fri Feb 13 11:28:10 2015, saint.snit@gmail.com wrote:
> 
> This is a bug report for perl from saint.snit@gmail.com,
> generated with the help of perlbug 1.39 running under perl 5.18.2.
> 
> 
> -----------------------------------------------------------------
> The "perlrecharclass" documentation -- both that shipped with perl
> 5.18.2
> and that appearing at http://perldoc.perl.org/perlrecharclass.html --
> contains an error.
> 
> It claims that the regular expression /[[]]/ "contains a character
> class containing just ], and the character class is followed by a ]".
> This does not appear to be an accurate description of this regular
> expression: the leading character class appears to contain just [.
> 

I believe the analysis is correct.

Here is the way the documentation appears in perl-5.10.1 (some whitespace trimmed):

#####
"[]"  =~ /[[]]/      #  Match, the pattern contains a character class
                     #  containing just ], and the character class is
                     #  followed by a ].
#####

Let's stipulate that the final ']' is outside the character class.  Then I ought to be able to rewrite the pattern to capture the contents of the character class, like so:

#####
my $capturing_pattern = qr/
    ([[])
    ]
    /x;
#####

Now let's test two different strings against this pattern:

#####
my @strings = ( '[]', ']]' );

for (my $i=0; $i<=$#strings; $i++) {
    say "Case ", $i+1, ":  string '$strings[$i]' ",
        ($strings[$i] =~ m/$capturing_pattern/) ? "matches" : "does not match";
    my $capture = $1;
    (defined $capture) ? say "Captured '$capture'" : say "undef";
}
#####

Outputs:

#####
Case 1:  string '[]' matches
Captured '['
Case 2:  string ']]' does not match
undef
#####

This suggests that the character class holds a single open-bracket '[' -- not a single close-bracket ']'.  This in turn suggests that the documentation is indeed wrong.

If others agree, I will patch pod/perlrecharclass.pod.

Thank you very much.


-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=123820

Thread Previous | 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