If I run this, it dies:#!/usr/bin/perl use strict; use warnings; my $MAX = 100; my $re = qr /^(1+)(??{"(?:$1){" . (length ($1) - 1) . "}" })$/; for (1 .. $MAX) {printf "%3d is a square\n" => $_ if (1 x $_) =~ /$re/} do {printf "%3d is a square\n" => $_ if (1 x $_) =~ /$re/} for 1 .. $ +MAX; map {printf "%3d is a square\n" => $_ if (1 x $_) =~ /$re/} 1 .. $ +MAX;
If I outcomment the map, it runs fine. If I lower $MAX to 70, it runs fine. If I lower $MAX to 70, and move the map statement to just before the for BLOCK, it dies as well:1 is a square 4 is a square 9 is a square 16 is a square 25 is a square 36 is a square 49 is a square 64 is a square 81 is a square 100 is a square 1 is a square 4 is a square 9 is a square 16 is a square 25 is a square 36 is a square 49 is a square 64 is a square 81 is a square 100 is a square 1 is a square 4 is a square 9 is a square 16 is a square 25 is a square 36 is a square 49 is a square Out of memory!
If I increase $MAX to 200, the program runs fine, regardless where the map is.1 is a square 4 is a square 9 is a square 16 is a square 25 is a square 36 is a square 49 is a square 64 is a square Out of memory!
My OS tools (ps, top, /proc, vmstat) don't indicate any abnormal memory usuage from the program, nor does any swapping to disk occur.
Am I doing something stupid without seeing it, or did I hit a bug in Perl?
Abigail
In reply to Unexpected 'Out of Memory' by Abigail-II
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |