Skip to content

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

Closed

Description

@p5pRT

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

Searchable as RT1744$

Activity

  1. p5pRT commented on Nov 4, 1999

    @p5pRT
    Author

    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();

  2. p5pRT commented on Nov 4, 1999

    @p5pRT
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions