zork42 has asked for the wisdom of the Perl Monks concerning the following question:

Hi.

Can anyone provide some insight into this weirdness please?

This was a complete pig (actually, more like a female dog) to find the cause of.

I've created a simple example script that shows the bastard issue.
Questions:
  1. In #2, why does prepending './' to the filename make 'die' produce the weird error message?
  2. In #3-#6 why does a 'die' with parameters suppress the weird error message?
  3. In #1-#6 what does '<GEN0>' in the 'die' messages mean?
Thanks!
---------------------------------------------------------------------- +---------------------------------------- example #1 >>>>> type weird.pl use strict; use warnings; use RTF::Tokenizer; my $tokenizer = RTF::Tokenizer->new( file => 'test.rtf' ); foreach ( 1 .. 5 ) { my ( $token_type, $argument, $parameter ) = $tokenizer->get_token( +); print " $token_type, $argument, $parameter\n"; } die; >>>>> weird.pl group, 1, control, rtf, 1 control, ansi, control, ansicpg, 1252 control, deff, 0 Died at D:\test\weird.pl line 13, <GEN0> line 1. ---------------------------------------------------------------------- +---------------------------------------- example #2 >>>>> type weird.pl use strict; use warnings; use RTF::Tokenizer; my $tokenizer = RTF::Tokenizer->new( file => './test.rtf' ); foreach ( 1 .. 5 ) { my ( $token_type, $argument, $parameter ) = $tokenizer->get_token( +); print " $token_type, $argument, $parameter\n"; } die; >>>>> weird.pl group, 1, control, rtf, 1 control, ansi, control, ansicpg, 1252 control, deff, 0 Can't call method "isa" without a package or object reference at C:/Pe +rl/site/lib/RTF/Tokenizer.pm line 170. ...propagated at D:\test\weird.pl line 13, <GEN0> line 1. ---------------------------------------------------------------------- +---------------------------------------- example #3 >>>>> type weird.pl use strict; use warnings; use RTF::Tokenizer; my $tokenizer = RTF::Tokenizer->new( file => './test.rtf' ); foreach ( 1 .. 5 ) { my ( $token_type, $argument, $parameter ) = $tokenizer->get_token( +); print " $token_type, $argument, $parameter\n"; } die ""; >>>>> weird.pl group, 1, control, rtf, 1 control, ansi, control, ansicpg, 1252 control, deff, 0 Can't call method "isa" without a package or object reference at C:/Pe +rl/site/lib/RTF/Tokenizer.pm line 170. ...propagated at D:\test\weird.pl line 13, <GEN0> line 1. ---------------------------------------------------------------------- +---------------------------------------- example #4 >>>>> type weird.pl use strict; use warnings; use RTF::Tokenizer; my $tokenizer = RTF::Tokenizer->new( file => './test.rtf' ); foreach ( 1 .. 5 ) { my ( $token_type, $argument, $parameter ) = $tokenizer->get_token( +); print " $token_type, $argument, $parameter\n"; } die 1; >>>>> weird.pl group, 1, control, rtf, 1 control, ansi, control, ansicpg, 1252 control, deff, 0 1 at D:\test\weird.pl line 13, <GEN0> line 1. ---------------------------------------------------------------------- +---------------------------------------- example #5 >>>>> type weird.pl use strict; use warnings; use RTF::Tokenizer; my $tokenizer = RTF::Tokenizer->new( file => './test.rtf' ); foreach ( 1 .. 5 ) { my ( $token_type, $argument, $parameter ) = $tokenizer->get_token( +); print " $token_type, $argument, $parameter\n"; } die "1"; >>>>> weird.pl group, 1, control, rtf, 1 control, ansi, control, ansicpg, 1252 control, deff, 0 1 at D:\test\weird.pl line 13, <GEN0> line 1. ---------------------------------------------------------------------- +---------------------------------------- example #6 >>>>> type weird.pl use strict; use warnings; use RTF::Tokenizer; my $tokenizer = RTF::Tokenizer->new( file => './test.rtf' ); foreach ( 1 .. 5 ) { my ( $token_type, $argument, $parameter ) = $tokenizer->get_token( +); print " $token_type, $argument, $parameter\n"; } die "one"; >>>>> weird.pl group, 1, control, rtf, 1 control, ansi, control, ansicpg, 1252 control, deff, 0 one at D:\test\weird.pl line 13, <GEN0> line 1. ---------------------------------------------------------------------- +----------------------------------------

Replies are listed 'Best First'.
Re: Very weird bug - insight would be helpful
by choroba (Cardinal) on Nov 19, 2013 at 08:37 UTC
    The behaviour is described in the first several paragraphs of perldoc -f die. Search for "if the output is empty". GEN0 refers to an input file handle.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Very weird bug - insight would be helpful
by zork42 (Monk) on Nov 19, 2013 at 16:10 UTC
    That makes sense, thanks!!

    So the eval at C:/Perl/site/lib/RTF/Tokenizer.pm line 170 just left this error lying around in $@:
    Can't call method "isa" without a package or object reference at C:/Perl/site/lib/RTF/Tokenizer.pm line 170.
    ?

    So good practice would be to always go $@ = '' after a failed eval?
    or use local $@?

    Should I report this as a bug to the Tokenizer.pm maintainer?
      Good practice is to use Try::Tiny, or at least
      eval { # Code that might die. 1; } or { # Handle the exception. }

      BTW, check whom you are replying to.

      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Thanks!

        Try::Tiny sounds good, I'll use that in my code.

        Please can you answer these questions if possible (to help my Perl indoctrination ;) )

        1. Would going $@ = '' after a failed eval work?
        2. Would use local $@ also work?
        3. Should I report this as a bug to the Tokenizer.pm maintainer?

        BTW, check whom you are replying to.
        I normally (almost always) use the "Comment on" link just under the OP.
        I'm not used to forums where you can reply to individual posts, most of the forums I use just allow you to add a new post to the end of the topic. Also I find I sometimes miss new comments that are added as replies to earlier comments.
        Is using the "Comment on" link OK? Or is using the reply-to-comment link preferred?