Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Strange interaction of bigint and foreach

by moritz (Cardinal)
on Apr 11, 2013 at 12:58 UTC ( [id://1028142]=note: print w/replies, xml ) Need Help??


in reply to Strange interaction of bigint and foreach

What happens is that the range operator .. is not overloadable. bigint works by overloading operators and literals, and since .. is not overloadable, it can't make bigint ranges work. And, more to the point here, the variables coming out of iterating a range are normal ints, and not bigints.

This is a known limitation, over which I've also stumbled in the past. I don't know if it's documented somewhere; if not, it really should be. Update: I've submitted a doc patch which mentions this problem in bigint.pm and overload.pm. Second Update: patch accepted, so perl 5.18 will contain the updated documentation.

Replies are listed 'Best First'.
Re^2: Strange interaction of bigint and foreach
by hdb (Monsignor) on Apr 11, 2013 at 13:09 UTC

    Very strange and dangerous... Some workarounds:

    use strict; use warnings; use bigint; print "\nWith two foreach loops:\n\n"; for my $j (20 .. 22) { for my $i (12 .. 14) { print $i ** ($j+0), "\n"; } } print "\nWith two foreach loops:\n\n"; for my $j (20 .. 22) { for my $i (12 .. 14) { print (((0+$i) ** $j), "\n"); } } print "\nWith two foreach loops:\n\n"; for my $j (20 .. 22) { for my $i (12 .. 14) { print ((0+$i) ** ($j+0), "\n"); } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1028142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-20 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found