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

[perl #134111] Global refalias access from sub

From:
James E Keenan via RT
Date:
May 16, 2019 17:22
Subject:
[perl #134111] Global refalias access from sub
Message ID:
rt-4.0.24-21672-1558027364-601.134111-14-0@perl.org
[This didn't show up well in RT, so I'm showing it here. -- JK]

On Thu, 16 May 2019 14:48:03 GMT, Thomas.Schweiger@rohde-schwarz.com wrote:
> I am not sure whether i have missed something maybe this little demo
> script demonstrates a bug:
> I expect SomeSub to print
> SomeSub: hashRef: a
> SomeSub: hash: a
> but it  does print:
> SomeSub: hashRef: a
> SomeSub: hash:
> 
> I tested it against perl 5.30-RC1 and 5.28.1 and both show the same
> behavior.
> 
> #!/usr/bin/env perl
> 
> use feature 'declared_refs';
> use feature 'refaliasing';
> no warnings "experimental::refaliasing";
> no warnings "experimental::declared_refs";
> 
> # Define a hash and assign it to a hashRef
> my $hashRef={ '1' => 'a' };
> 
> # Alias %hash to the previously defined hashRef
> \my %hash=$hashRef;
> 
> # Access the (global) $hashRef and the (global) aliased %hash.
> # This works fine. Both print the same.
> print "hashRef: ${$hashRef}{'1'}\n";
> print "hash: $hash{'1'}\n";
> 
> # Call SomeSub
> SomeSub();
> 
> # A sub that accesses the (global) $hashRef and the (global) aliased
> %hash.
> # Here is the problem: access via $hashRef works, but access via %hash
> does not.
> # Did I miss something here or could this be a bug?
> sub SomeSub {
>             print "SomeSub: hashRef: ${$hashRef}{'1'}\n";
>             print "SomeSub: hash: $hash{'1'}\n";
> }
> 
> # In the latest perl 5.30-RC1, this prints:
> # hashRef: a
> # hash: a
> # SomeSub: hashRef: a
> # SomeSub: hash:


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



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