in reply to Re: Extracting a hash reference from a string
in thread Extracting a hash reference from a string

The text 'Compilation failed...' is added by the require() function. It appears that require() adds this text to whatever is returned by the compilation process - in this case the hash ref from die().
  • Comment on Re: Re: Extracting a hash reference from a string

Replies are listed 'Best First'.
Re: Re: Re: Extracting a hash reference from a string
by jand (Friar) on Mar 23, 2003 at 03:35 UTC
    Yes, you are right. The require opcode always appends the string to $@, regardless if it is an object or not. Note that this will stringify your reference and then decrement the reference count to your hash. So don't try to access it through the pointer provided by the stringification (which would be a bad idea anyways).

    I guess this means you will have to use a different error mechanism if your required modules can fail in a variety of ways. You could adopt some convention of package variables, like this:

    eval { require MyModule } if (defined $MyModule::Error) { print "Couldn't load MyModule: ", $MyModule::Error->{message}, + "\n"; # ... }
    and in your MyModule.pm file:
    package MyModule; our $Error; # ... if ($some_error) { $Error = {err = 42, message => 'Sorry, my fault!'}; die; # or maybe just 'return 0;' }