> > that doesn't make sense to me.

My scripts read a file. Say the file looks like this:

BLOCK1
my $div=42/0;
BLOCK2
open(my $fh,"n0n ex1$t#nt filename" or die;
BLOCK3
if($health<0){die "you died of dysentary";}


My script reads the entire file in first, closes the filehandle,
and passes the text along for later processing.

Say processing includes getting BLOCK2 and doing an eval() on the string.

eval($blk2);
die $@ if($@);

This will die because the string is "open or die".
and its tryign to open a nonexistent file so it dies.
ANd then script prints out $@, it will print out the error
occured at line 1 of eval string.
because there is only 1 line in the string being evaled.

THere were 3 different blocks of code in the textfile.txt,
but I only evaled one of them.

If "open or die" is on line FOUR of the original file,
and if I do an eval like this:

eval("#line3 textfile.txt\n eval or die");
die $@ if($@);

THen it will print that the error occurred at line 4 of textfile.txt.

before, I was getting error messages at line 1 of eval string.
I did a quick check and #line is printing out error messages
at line 4 of textfile.txt, which is exactly what I needed.


Greg


On Fri, October 25, 2019 10:06 pm, Uri Guttman wrote:
> On 10/25/19 9:17 PM, Greg London wrote:
>
>> ahh...  #line   that's it!
>>
>>
>> $. wouldn't work for me becuase the filehandle is long since
>> closed by the time I do the eval(), so it will come back 0
>>
>> I'll have to prepend #line to the eval string
>> and figure out the line number to put there, but that'll make these
>> scripts I'm dealing with a whole lot easier to use.
> that doesn't make sense to me. i think you need __LINE__ . #line will set
> the line number to whatever you want. if you insert more lines before the
> eval, then it will be off. __LINE__ is correctly set to the current line
> number by the compiler.
>
> uri
>
> _______________________________________________
> Boston-pm mailing list
> Boston-pm@pm.org
> https://mail.pm.org/mailman/listinfo/boston-pm
>
>


-- 

_______________________________________________
Boston-pm mailing list
Boston-pm@pm.org
https://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to