in reply to RE: RE: Re: How to tell eval where the code is from
in thread How to tell eval where the code is from

No need to bug P5P. The feature I posted about has been in there since Perl version 2, I think.

-- Randal L. Schwartz, Perl hacker

  • Comment on RE: RE: RE: Re: How to tell eval where the code is from

Replies are listed 'Best First'.
RE: RE: RE: RE: Re: How to tell eval where the code is from
by tilly (Archbishop) on Aug 08, 2000 at 16:41 UTC
    Live and learn!

    Is this documented anywhere? Other than in your brain and the code?

      perlsyn (yeah, the one nobody reads {grin}) says:
      Plain Old Comments (Not!) Much like the C preprocessor, Perl can process line directives. Using this, one can control Perl's idea of filenames and line numbers in error or warning messages (especially for strings that are processed with eval()). The syntax for this mechanism is the same as for most C preprocessors: it matches the regular expression /^#\s*line\s+(\d+)\s*(?:\s"([^"]*)")?/ with $1 being the line number for the next line, and $2 being the optional filename (specified within quotes). Here are some examples that you should be able to type into your command shell:
      and goes on to give some examples.

      -- Randal L. Schwartz, Perl hacker

        I actually did read perlsyn. I even go back and browse it periodically for fun. I have even written code that had no purpose other than to play with features that I found there. (For instance a program that was designed as a finite state machine, switching states with "goto &foo;".) I sincerely missed this particular point. Actually I remember seeing it, and not seeing why it would be useful, then forgetting it again.

        That said, unless I am missing something obvious, I find the above feature to be buggy for perl 5.005_03 on both Windows and Linux. Here is my test:

        $ perl $str = <<FOO; # line 1 "foo" sub bar { die('gotcha'); } &bar(); FOO print "When executed by eval:\n"; eval($str); print $@; print "When executed by perl:\n"; open (PERL, "| perl") or die "Cannot start perl: $!"; print PERL $str; close PERL; __END__ When executed by eval: gotcha at (eval 1) line 3. When executed by perl: gotcha at foo line 2.
        When I go home tonight I will try this on 5.6 and send a bug report in if I still cannot get it to work.

        For the record, I consider myself a Perl hacker, not a perl hacker. (VBG)