Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"local %MYPKG::;" causes $MYPKG::FOO and ${"MYPKG::FOO"} to differ #816

Closed
p5pRT opened this issue Nov 4, 1999 · 2 comments
Closed

"local %MYPKG::;" causes $MYPKG::FOO and ${"MYPKG::FOO"} to differ #816

p5pRT opened this issue Nov 4, 1999 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 4, 1999

Migrated from rt.perl.org#1744 (status was 'resolved')

Searchable as RT1744$

@p5pRT
Copy link
Author

p5pRT commented Nov 4, 1999

From rnewman@northernlight.com

It prints the following output​:

"" ""
"green" "green"
"red" "red"
"red" ""
"blue" ""
"blue" "yellow"
"blue" "blue"

when it should, in my opinion, print this​:

"" ""
"green" "green"
"red" "red"
"" ""
"blue" "blue"
"yellow" "yellow"
"red" "red"

#!/usr/bin/perl
use strict;
no strict 'refs';

sub foo {
  local %MYPKG​:: ;
  dumpit();
  $MYPKG​::COLOR = "blue";
  dumpit();
  ${"MYPKG​::COLOR"} = "yellow";
  dumpit();
}

sub dumpit {
  print qq("), $MYPKG​::COLOR, qq(" );
  print qq("), ${"MYPKG​::COLOR"}, qq("\n);
}

dumpit();
$MYPKG​::COLOR = "green";
dumpit();
${"MYPKG​::COLOR"} = "red";
dumpit();
foo();
dumpit();

@p5pRT
Copy link
Author

p5pRT commented Nov 4, 1999

From [Unknown Contact. See original ticket]

Ron Newman writes​:

Here's a program that uses the statement "local %MYPKG​::;", and then
finds that the variables $MYPKG​::FOO and ${"MYPKG​::FOO"} have
different values.
I don't see how this can ever correctly happen to a package variable.

The address of $MYPKG​::FOO is known at compile-time.
The address of ${"MYPKG​::FOO"} is not.

Therefore the local() is screwing the latter but not the former.

Short solution​: don't do that :-)

Nat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant