Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Actually, it is not a scoping issue. By that logic, this should also save memory:
sub get_size { my @a = big_list(); return scalar @a } my $size = get_size();

However, in a simple test, that uses the same memory as a global array that does the same thing.

Perl, generally speaking, does not release memory back to the OS unless your system is running out of memory. The memory from lexical variables can be claimed and reused by Perl, but it doesn't go back to the OS.

All of the other methods created an array in addition to what was copied on the stack. map only creates an array of 1s in addition to what was copied on the stack; thus it uses less memory (unless your original data is no bigger than integers, of course) (and yes, this was not always true in older versions of Perl).



When's the last time you used duct tape on a duct? --Larry Wall

In reply to Re^3: Trouble getting size of list returned from sub by ColonelPanic
in thread Trouble getting size of list returned from sub by wanna_code_perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [ambrus]: This is different from MS Word, which was already a good editor in the pre-unicode days (in word for windows versions 2 and 6, which ran on windows 3 but also on windows 95), only it wasn't trying to solve the task of writing maths papers back then.
    [Discipulus]: ah ok, sounds reasonable; with no fear: Perl all life long
    [ambrus]: Mind you, LaTeX is currently still useful for writing math paper or snippet content without styling in such a way that the
    [ambrus]: formatting conventions of a journal or website can be quickly applied to it, and MS Office and LibreOffice has not quite solved this (although it's better for this than it used to be),
    [ambrus]: which is sort of a drawback compared to the ages of typewritten manuscripts representing content only to which the typesetter applies formatting, but that process required much more manual labor.
    [ambrus]: If you want to typeset a manuscript, you can still do much less work then in the manual typesetting ages and get good formatting.
    [ambrus]: All with only cheap modern computers and software.
    [ambrus]: Something you can have at home and your corner print shop, without a whole printing press's worth of equipment.

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (9)
    As of 2017-09-26 11:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      During the recent solar eclipse, I:









      Results (293 votes). Check out past polls.

      Notices?