- publishing free software manuals
Perl Language Reference Manual
by Larry Wall and others
Paperback (6"x9"), 724 pages
ISBN 9781906966027
RRP £29.95 ($39.95)

Sales of this book support The Perl Foundation! Get a printed copy>>>

28.1.13 System Resources

If your code is destined for systems with severely constrained (or missing!) virtual memory systems then you want to be especially mindful of avoiding wasteful constructs such as:

# NOTE: this is no longer "bad" in perl5.005
for (0..10000000) {}                       # bad
for (my $x = 0; $x <= 10000000; ++$x) {}   # good
my @lines = <$very_large_file>;            # bad
while (<$fh>) {$file .= $_}                # sometimes bad
my $file = join(”, <$fh>);                # better

The last two constructs may appear unintuitive to most people. The first repeatedly grows a string, whereas the second allocates a large chunk of memory in one go. On some systems, the second is more efficient that the first.

ISBN 9781906966027Perl Language Reference ManualSee the print edition