| [reply] |
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 | [reply] [d/l] |
$ 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) | [reply] [d/l] |