bigint and eval

Y

Yakov

When I add 'use bigint' to the working program, it stops working.

I tracked the problem to eval(). eval() (evaluates simple arithmetic
expression gioven as string) works without bigint, but stops working
when bigint is added:

perl -e '$expr="1+2"; print eval($expr)' # prints 3 as expected
-- works

perl -e 'use bigint; $expr="1+2"; print eval($expr)' #prints
nothing
-- stops working when 'use bigint' is added

How do I fix eval() in the presence of 'use bigint' ?

Thanks
Yakov
 
A

anno4000

Yakov said:
When I add 'use bigint' to the working program, it stops working.

I tracked the problem to eval(). eval() (evaluates simple arithmetic
expression gioven as string) works without bigint, but stops working
when bigint is added:

perl -e '$expr="1+2"; print eval($expr)' # prints 3 as expected
-- works

perl -e 'use bigint; $expr="1+2"; print eval($expr)' #prints
nothing
-- stops working when 'use bigint' is added

How do I fix eval() in the presence of 'use bigint' ?

Start with finding out what went wrong in th first place. Print $@
after the eval.

Anno
 
Y

Yakov

Start with finding out what went wrong in th first place. Print $@
after the eval.

Anno

'print $@' prints
error isConstant(undef): $^H{integer} is not defined at (eval 5) line
1, at end of line
Constant(undef): $^H{integer} is not defined at (eval 5) line 1, at
end of line

Yakov
 
A

anno4000

Yakov said:
'print $@' prints
error isConstant(undef): $^H{integer} is not defined at (eval 5) line
1, at end of line
Constant(undef): $^H{integer} is not defined at (eval 5) line 1, at
end of line

It looks like the bigint pragma only works with perl5.9.* and better.
That's arguably a bug, the module should check the version.

Anno
 
M

Mumia W.

When I add 'use bigint' to the working program, it stops working.

I tracked the problem to eval(). eval() (evaluates simple arithmetic
expression gioven as string) works without bigint, but stops working
when bigint is added:

perl -e '$expr="1+2"; print eval($expr)' # prints 3 as expected
-- works

perl -e 'use bigint; $expr="1+2"; print eval($expr)' #prints
nothing
-- stops working when 'use bigint' is added

How do I fix eval() in the presence of 'use bigint' ?

Thanks
Yakov

For reasons that I haven't figured out yet, the "use bigint;" has to be
within the eval():

perl -le 'print eval("use bigint; 1+2")'

Maybe Perl is using a source filter to change ordinary Perl numbers into
something else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top