bigint and eval

Discussion in 'Perl Misc' started by Yakov, Mar 20, 2007.

  1. Yakov

    Yakov Guest

    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
     
    Yakov, Mar 20, 2007
    #1
    1. Advertising

  2. Yakov

    -berlin.de Guest

    Yakov <> 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
     
    -berlin.de, Mar 20, 2007
    #2
    1. Advertising

  3. Yakov

    Yakov Guest

    On Mar 20, 10:07 am, -berlin.de wrote:
    > Yakov <> 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
     
    Yakov, Mar 20, 2007
    #3
  4. Yakov

    -berlin.de Guest

    Yakov <> wrote in comp.lang.perl.misc:
    > On Mar 20, 10:07 am, -berlin.de wrote:
    > > Yakov <> 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
     
    -berlin.de, Mar 20, 2007
    #4
  5. Yakov

    Mumia W. Guest

    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.
     
    Mumia W., Mar 20, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Bazell

    BigInt leading plus sign

    Dave Bazell, Dec 13, 2005, in forum: Perl
    Replies:
    2
    Views:
    2,618
    Dave Bazell
    Dec 14, 2005
  2. KK

    bigInt operator* help

    KK, Oct 10, 2003, in forum: C++
    Replies:
    3
    Views:
    862
    rossum
    Oct 12, 2003
  3. MK
    Replies:
    10
    Views:
    2,870
    DHOLLINGSWORTH2
    Feb 27, 2005
  4. MK
    Replies:
    1
    Views:
    1,619
  5. MaggotChild
    Replies:
    1
    Views:
    187
    MaggotChild
    Oct 28, 2009
Loading...

Share This Page