package My::Class; use strict; use warnings; use Class::Struct; use IO::File;
struct MyStruct => { f1 => '$', f2 => '$' }; sub new { my ($class, $ifname) = @_; my $s = {}; $class = ref($class) || $class; bless ($s, $class); $s->{FILE} = new IO::File($ifname, "r"); if ( !defined($s->{FILE}) ) { print("ERROR: $class: cannot open $ifname for reading\n"); exit(-1); } return $s; } sub f { return MyStruct->new(); } sub DESTROY { $s->{FILE}->close(); } ---------------------------------------------------------------------------------- if i make a perl script that uses My::Class and i construct an instance of My::Class and then call My::Class::f(), i get the following error: Can't locate object method "new" via package "MyStruct" (perhaps you forgot to load "MyStruct"?) now obviously the problem is not that no new() method exists for MyStruct, but rather that i forgot to declare $s in DESTROY(). it took me literally hours to figure out what the problem was. i mean, could the error message be anymore unrelated to the real problem? what the hell does $s not being declared in DESTROY() have anything to do with the error message i was given? thanks for the help and advice. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>