develooper Front page | perl.perl5.porters | Postings from December 2012

[perl #116086] split "\x20" doesn't work as documented

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
December 14, 2012 02:37
Subject:
[perl #116086] split "\x20" doesn't work as documented
Message ID:
rt-3.6.HEAD-17500-1355452638-134.116086-15-0@perl.org
On Thu Dec 13 09:32:33 2012, estrai wrote:
> This is a bug report for perl from estrai@estrai.com,
> generated with the help of perlbug 1.39 running under perl 5.17.7.
> 
> 
> -----------------------------------------------------------------
> 
> Hi,
> split() has a special case for " " and "\x20" so they work like \s+
> (see perldoc -f split for details)
> In blead (also observed on 5.17.5) "\x20" doesn't seem to work as
>    documented.
> 
>  * " " works as expected:
> 
> % perl -MData::Dumper -E '$_="  a   b c   "; print Dumper [ split " "
>    ]'
> $VAR1 = [
>           'a',
>           'b',
>           'c'
>         ];
> 
>  * "\x20" doesn't:
> 
> % perl -MData::Dumper -E '$_="  a   b c   "; print Dumper [ split
>    "\x20" ]'
> $VAR1 = [
>           '',
>           '',
>           'a',
>           '',
>           '',
>           'b',
>           'c'
>         ];
> 
> estrai.
> 

On 5.16.0 (at least), I get different results from yours:

#####
$ perl -MData::Dumper -E '$_ = "\x20a\x20b\x20c\x20";@r=split /\x20/;say
Dumper \@r;'
$VAR1 = [
          '',
          'a',
          'b',
          'c'
        ];

$ perl -MData::Dumper -E '$_ = " a b c ";@r=split /\x20/;say Dumper \@r;'
$VAR1 = [
          '',
          'a',
          'b',
          'c'
        ];
#####

Nonetheless, these results appear to fail to match the documentation in
a *different* way from yours, viz., they fail the specification that
"any leading whitespace in EXPR is removed before splitting occurs."

Thank you very much.
Jim Keenan

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

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