5plit_func has asked for the wisdom of the Perl Monks concerning the following question:

Dear perlmonks, I have a question to ask that baffles me. While coding i just decided to try out a way to flood my operating system with Perl's request i all i got was a message saying (Out of Memory!) without getting any sort of warnings from Perl even though strict,warnings ,diagnostic where enabled. Please can any one tell me why i got this message. see the code i used for the request.
my $flood_network = "********************\n" x 1_000_000_000_000; print("$flood_network");

Replies are listed 'Best First'.
Re: Out of memory! without system errors
by BrowserUk (Patriarch) on Dec 05, 2013 at 01:45 UTC
    all i got was a message saying (Out of Memory!) without getting any sort of warnings from Perl

    The Out of memory message is a warning from Perl; telling you you've asked for more memory -- ~20,000GB -- than your system has available.

    You could achieve your expected result by doing:

    print "********************\n" for 1 .. 1_000_000_000_000;

    Of course, you might have to wait a while.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      BrowserUk, thank you very much for your explanation i am humbled by your explanation and alternative given to achieve my playfulness using Perl.
Re: Out of memory! without system errors
by Athanasius (Archbishop) on Dec 05, 2013 at 03:39 UTC

    As BrowserUk says, the message you’re getting is a Perl runtime error. To confirm this for yourself, use the block form of eval:

    13:38 >perl -Mstrict -wE "eval { my $s = '*' x 1e12; say $s; }; warn q +q[\nPerl runtime error: $@] if $@;" Perl runtime error: Out of memory during string extend at -e line 1. 13:38 >

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      :) I can't actually trigger that error with that code on my win32 perl ... and its an old machine with 500mb

        I bet you're running a pre-5.10 version of Perl.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Out of memory! without system errors (bartender)
by Anonymous Monk on Dec 05, 2013 at 01:37 UTC

    Please can any one tell me why i got this message.

    Because you're out of memory

    Its like you walk into a bar, and ask the bartender for whiskey, and the bartender says "out of whiskey"

Re: Out of memory! without system errors
by Laurent_R (Canon) on Dec 05, 2013 at 07:30 UTC
    In a way, Perl is being quite nice with you: it warns you that you are requesting too much memory and stops running, rather than actually exhausting the memory and bringing your system down.