I may well be in over my head here, but I just happened to be reading about this area only yesterday. I'm wondering if the section "References Don't Work As Hash Keys" on p265 of Camel 3rd edn applies here?
HTH, GStC. -----Original Message----- From: Siddharth Uppal [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 16, 2005 12:41 AM To: beginners@perl.org Subject: Class::MethodMaker Query Hi, Since yesterday I've been scratching my head over the different behavior of the two pieces of codes listed under "listing-1" and "listing-2", because I expect the two to behave in a similar manner. ------------------start listing-1----------------------- package Foo; use strict; use warnings 'all'; # Member fields with their default values our %_FIELD_DEFAULTS = ( 'a' => "def1" , 'b' => "def2" , 'c' => "def3" ); my @fields = (keys %_FIELD_DEFAULTS); # Automatically generate the constructor and get/set methods use Class::MethodMaker 'new_with_init' => "new" , 'new_hash_init' => "_hash_init" , 'get_set' => ['a', 'b', 'c'] ; 1; ------------------end listing-1----------------------- and ------------------start listing-2----------------------- package Foo; use strict; use warnings 'all'; our %_FIELD_DEFAULTS = ( 'a' => "def1" , 'b' => "def2" , 'c' => "def3" ); my @fields = (keys %_FIELD_DEFAULTS); # Automatically generate the constructor and get/set methods use Class::MethodMaker 'new_with_init' => "new" , 'new_hash_init' => "_hash_init" , 'get_set' => [EMAIL PROTECTED]; # Pass a ref to the array! 1; ------------------end listing-2----------------------- I expect Listing-1 and Listing-2 to do the same thing, but they actually appear to behave differently. I have a perl script test.pl that instantiates an object of Foo package. The script looks like this: -----------------start listing-3----------------------- #! /usr/local/bin/perl -w use strict; use warnings 'all'; use Foo; my $obj = Foo->new(a => 1, b => 2, c=> 3); print $obj->a(), "\n"; print $obj->b(), "\n"; print $obj->c(), "\n"; -----------------end listing-3----------------------- If I use the code of Foo.pm listed under listing-1, I get the expected output (i.e. 1, 2, 3 printed on separate lines), but if I use the code of Foo.pm listed under listing-2, I get an error that says: Can't locate object method "a" via package "Foo" (perhaps you forgot to load "Foo"?) at blib/lib/Class/MethodMaker.pm (autosplit into blib/lib/auto/Class/MethodMaker/new_hash_init.al) line 342. I need help in figuring out why this is happening? I would appreciate if anyone could help clear things out for me! Thanks, Amit -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>