Home > Archive > PERL Beginners > November 2004 > RE: Spam:Re: Using regular expressions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RE: Spam:Re: Using regular expressions
|
|
| Michael Kraus 2004-11-25, 3:55 am |
| 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 =3D <INFILE> ) {
# stuff
}
If you are going to correct me, at least get it right and do it in a
friendly manner! ;) :P :)
Regards,
=20
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
=20
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.
=20
> -----Original Message-----
> From: John W. Krahn [mailto:krahnj@telus.net]=20
> Sent: Thursday, 25 November 2004 11:17 AM
> To: Perl Beginners
> Subject: Spam:Re: Using regular expressions
>=20
> Michael S. E. Kraus wrote:
>=20
> Hello,
>=20
> memory and=20
> have alot of=20
> changes, and=20
> ^^^^^^^^^^^^^^^^
>=20
> You should *always* verify that the files were opened correctly.
>=20
> open INFILE, '<', $filename or die "Cannot open $filename: $!";
> open OUTFILE, '>', "$filename.$$" or die "Cannot open=20
> $filename.$$: $!";
>=20
>=20
>=20
> You imply above that you will read the file "a line at a=20
> time" however using a for loop will read the whole file into=20
> a list in memory. You need to use a while loop to read a=20
> line at a time.
>=20
> while ( my $line =3D <INFILE> ) {
>=20
>=20
>=20
> You should verify that rename worked correctly
>=20
> rename "$filename.$$", $filename or die "Cannot rename=20
> $filename.$$: $!";
>=20
>=20
>=20
> John
> --
> use Perl;
> program
> fulfillment
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org For=20
> additional commands, e-mail: beginners-help@perl.org=20
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20
>=20
>=20
| |
| John W. Krahn 2004-11-25, 3:55 am |
| [ 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
|
|
|
|
|