develooper Front page | perl.perl5.porters | Postings from January 2019

Re: [perl #133782] length($^R) sometimes wrong

Thread Previous | Thread Next
From:
Hauke D
Date:
January 19, 2019 15:20
Subject:
Re: [perl #133782] length($^R) sometimes wrong
Message ID:
2793dd98-241b-8807-48bc-153448a761a7@zero-g.net
Hi,

On 19.01.19 15:39, James E Keenan via RT wrote:
 > With a slightly rewritten -- but possibly incorrectly rewritten --
 > version of your longer program, I get different results.  See
 > attachment.

Apparently something as simple as copying $^R into another variable 
fixes it. It also seems that a call to length() is required to trigger 
this issue in the first place. Note the "CUR = 1" vs. "MG_LEN = 2" in 
the output of the following, maybe that has something to do with it, I 
don't know enough about the internals to say...

  use Devel::Peek;
  while ( "\N{U+E4}bc" =~ /(..?)(?{$^N})/g ) {
      Dump($^R);
      Dump(my $r = $^R);
      print STDERR length($^R), "\n";
  }

Regards,
-- Hauke D


On 19.01.19 15:39, James E Keenan via RT wrote:
> On Sat, 19 Jan 2019 13:45:44 GMT, haukex@zero-g.net wrote:
>> Hi everyone,
>>
>> This oneliner fails, when it most likely shouldn't:
>>
>>    perl -e 'while( "\N{U+E4}bc" =~ /(..?)(?{$^N})/g )
>>             { length($^R)==length("$^R") or die }'
>>
>> A slightly longer test program (attached) shows that on the second
>> iteration, length($^R) is reporting 2 instead of the expected 1. It
>> seems to have something to do with UTF8 strings, since it works fine on
>> non-UTF8 strings.
>>
>> Tested on several versions of Perl on Linux and Windows (down to 5.8.9).
>>
>> Regards,
>> -- Hauke D
> 
> With a slightly rewritten -- but possibly incorrectly rewritten -- version of your longer program, I get different results.  See attachment.
> 
> 

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