Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Strange interaction of bigint and foreach

by moritz (Cardinal)
on Apr 11, 2013 at 12:58 UTC ( #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.


Comment on Re: Strange interaction of bigint and foreach
Download Code
Re^2: Strange interaction of bigint and foreach
by hdb (Parson) 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
Node Status?
node history
Node Type: note [id://1028142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-08-23 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls