Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > bigint and eval

Reply
Thread Tools

bigint and eval

 
 
Yakov
Guest
Posts: n/a
 
      03-20-2007
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

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      03-20-2007
Yakov <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> 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
 
Reply With Quote
 
 
 
 
Yakov
Guest
Posts: n/a
 
      03-20-2007
On Mar 20, 10:07 am, (E-Mail Removed)-berlin.de wrote:
> Yakov <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>
> > 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


'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

 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      03-20-2007
Yakov <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> On Mar 20, 10:07 am, (E-Mail Removed)-berlin.de wrote:
> > Yakov <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> >
> > > 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

>
> '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
 
Reply With Quote
 
Mumia W.
Guest
Posts: n/a
 
      03-20-2007
On 03/20/2007 08:47 AM, Yakov wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math::GMP and Pari Installed, But BigInt Can't Find Them MaggotChild Perl Misc 1 10-28-2009 04:30 PM
Different behavior between eval "07" and eval "08" Liang Wang Perl Misc 8 02-02-2008 08:31 PM
DataBinder.Eval and Eval. craigkenisston@hotmail.com ASP .Net 1 06-16-2006 05:33 PM
BigInt leading plus sign Dave Bazell Perl 2 12-14-2005 08:59 PM
bigInt operator* help KK C++ 3 10-12-2003 08:31 PM



Advertisments