[ Please do not top-post.  TIA ]

[ Please trim your posts. ( excess message trimmed )  TIA ]


Michael Kraus wrote:
John,

Lighten up matey...

The examples I've given are just that examples... Error checking
functionality is up the end programmer... (And you are quite right, you
should check the status of operations.)  This is a beginers list, let's
keep it friendly, eh?


... and FWIW ...

for my $line (<INFILE>) {
        # stuff
}

is equivalent to:

while (my $line = <INFILE>) {
        # stuff
}

If you are going to correct me, at least get it right and do it in a
friendly manner! ;) :P :)

perldoc -q "How can I make my Perl program take less memory" perldoc -q "How can I read in an entire file all at once"

perldoc perlop
[snip]
       I/O Operators

       [snip]

       The following lines are equivalent:

           while (defined($_ = <STDIN>)) { print; }
           while ($_ = <STDIN>) { print; }
           while (<STDIN>) { print; }
           for (;<STDIN>;) { print; }
           print while defined($_ = <STDIN>);
           print while ($_ = <STDIN>);
           print while <STDIN>;

       [snip]

       If a <FILEHANDLE> is used in a context that is looking for a list, a
       list comprising all input lines is returned, one line per list element.
       It's easy to grow to a rather large data space this way, so use with
       care.

perldoc perlsyn
[snip]
       Compound Statements

       In Perl, a sequence of statements that defines a scope is called a
       block.  Sometimes a block is delimited by the file containing it (in
       the case of a required file, or the program as a whole), and sometimes
       a block is delimited by the extent of a string (in the case of an
       eval).

       But generally, a block is delimited by curly brackets, also known as
       braces.  We will call this syntactic construct a BLOCK.

       The following compound statements may be used to control flow:

           if (EXPR) BLOCK
           if (EXPR) BLOCK else BLOCK
           if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK
           LABEL while (EXPR) BLOCK
                        ^^^^
           LABEL while (EXPR) BLOCK continue BLOCK
                        ^^^^
           LABEL for (EXPR; EXPR; EXPR) BLOCK
                            ^^^^
           LABEL foreach VAR (LIST) BLOCK
                              ^^^^
           LABEL foreach VAR (LIST) BLOCK continue BLOCK
                              ^^^^
           LABEL BLOCK continue BLOCK

[ emphasis added ]


$ wc < test-file.txt
4328 10551 153707
$ perl -e'system "free","-ob"; while ( <> ) { system "free","-ob"; last }' test-file.txt
total used free shared buffers cached
Mem: 261013504 256503808 4509696 0 42680320 116006912
Swap: 348356608 5406720 342949888
total used free shared buffers cached
Mem: 261013504 256503808 4509696 0 42680320 116006912
Swap: 348356608 5406720 342949888
$ perl -le'print 256503808 - 256503808'
0
$ perl -e'system "free","-ob"; for ( <> ) { system "free","-ob"; last }' test-file.txt
total used free shared buffers cached
Mem: 261013504 256503808 4509696 0 42680320 116006912
Swap: 348356608 5406720 342949888
total used free shared buffers cached
Mem: 261013504 257056768 3956736 0 42680320 116006912
Swap: 348356608 5406720 342949888
$ perl -le'print 257056768 - 256503808'
552960




Michael S. E. Kraus
Software Developer
Wild Technology Pty Ltd
_______________________________
ABN 98 091 470 692
Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
Telephone 1300-13-9453 | Facsimile 1300-88-9453
http://www.wildtechnology.net
The information contained in this email message and any attachments may
be confidential information and may also be the subject of client legal
- legal professional privilege. If you are not the intended recipient,
any use, interference with, disclosure or copying of this material is
unauthorised and prohibited. This email and any attachments are also
subject to copyright. No part of them may be reproduced, adapted or
transmitted without the written permission of the copyright owner. If
you have received this email in error, please immediately advise the
sender by return email and delete the message from your system.

Are you going to sue me?



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to