Re: Using regular expressions
From: Gunnar Hjalmarsson (noreply_at_gunnar.cc)
Date: 11/25/04
- Next message: Michael Kraus: "RE: Spam:RE: Spam:Re: Using regular expressions"
- Previous message: Michael Kraus: "RE: Overridden methods"
- In reply to: Michael Kraus: "RE: Spam:Re: Using regular expressions"
- Next in thread: John W. Krahn: "Re: Spam:Re: Using regular expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Thu, 25 Nov 2004 01:39:20 +0100
[ Please do not quote the whole message you are responding to, but only
what's needed to give context. Also, please type your reply *below* the
part(s) of the message you are commenting on. ]
Michael Kraus wrote:
> John W. Krahn wrote:
>>
>> You should *always* verify that the files were opened correctly.
>>
>> open INFILE, '<', $filename or die "Cannot open $filename: $!";
>> open OUTFILE, '>', "$filename.$$" or die "Cannot open $filename.$$: $!";
>>
>>> for my $line (<INFILE>) {
>>
>> You imply above that you will read the file "a line at a time" however
>> using a for loop will read the whole file into a list in memory. You
>> need to use a while loop to read a line at a time.
>>
>> while ( my $line = <INFILE> ) {
<snip>
>> You should verify that rename worked correctly
>>
>> rename "$filename.$$", $filename or die "Cannot rename $filename.$$: $!";
>
> 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?
Yes, this is a beginner level list, which makes it extra important to
apply good programming practices in posted example code. Pointing out
shortcomings in that respect is not unfriendly, it's useful advice.
> ... and FWIW ...
>
> for my $line (<INFILE>) {
> # stuff
> }
>
> is equivalent to:
>
> while (my $line = <INFILE>) {
> # stuff
> }
No, it's not. John explained why.
Please read up on the topic, e.g. in "perldoc perlsyn", before objecting
again.
> If you are going to correct me, at least get it right and do it in a
> friendly manner! ;) :P :)
???
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
- Next message: Michael Kraus: "RE: Spam:RE: Spam:Re: Using regular expressions"
- Previous message: Michael Kraus: "RE: Overridden methods"
- In reply to: Michael Kraus: "RE: Spam:Re: Using regular expressions"
- Next in thread: John W. Krahn: "Re: Spam:Re: Using regular expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|