in reply to Accessing Other Globals?

It's because $foo::A_GLOBAL is equivalent to getting the scalar A_GLOBAL in the package foo (which of course does not exist).


update Now you're accessing an array A_GLOBAL in the package foo, not Foo. Perl is case sensitive, after all.

[ ar0n -- want job (boston) ]

Replies are listed 'Best First'.
Re: Re: Accessing Other Globals?
by Foo::Bar (Acolyte) on Dec 15, 2001 at 02:53 UTC
    update Now you're accessing an array A_GLOBAL in the package foo, not Foo. Perl is case sensitive, after all.

    I should explain myself better. I have an object $foo but don't know for sure what pacakge it is from. How do I access it's globals?
      my $package = ref($foo); if ($package) { no strict 'refs'; @global_array = @{"$package::A_GLOBAL_ARRAY"}; }
      Please note that using global arrays is a sign that you have no idea how to correctly program your design (if you even have one). This is especially true if you're doing OO programming.

      If you want to work with "global arrays", look into using Exporter.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        Please note that using global arrays is a sign that you have no idea how to correctly program your design (if you even have one)

        Thank you for your help and the answer but to make this sort of a blanket statement is really nasty. You have no idea what I am doing with this. Perhaps I just want to learn something. Not only that but there are times when a global variable makes perfect sense. Do you respond the same way when someone brings up the goto statement? Get off your horse buddy.
Re: Re: Accessing Other Globals?
by Foo::Bar (Acolyte) on Dec 15, 2001 at 02:42 UTC
    Ooops tat was a type that should be:

    my @array = @foo::A_GLOBAL

    Which fails with no error...
      Perl is case-sensitive. 'foo' is not the same as 'Foo'.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        As I said, I should have explained myself better. I have an object $foo and want to access its global variables without making the assumption it is in pacakge Foo.