Re: Perl script does not work



"CSUIDL PROGRAMMEr" <syedamjad_a@xxxxxxxxx> wrote in
news:1146333247.131872.286590@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:

foreach my $file ( @files ) {

FILES: foreach my $file ( @files ) {

open(OLD, "<$file") or push @errors, "failed to open $file: $!";

It is good that you check for errors, but

* Further down, you still attempt to read from this file. You should
stop processing this file if you cannot open it

* Use lexical filehandles.

* perldoc -q vars

* You don't need the paratheses in the open call as you are using the
lower precedence or rather than ||.

* Use the three argument form of open.

unless ( open my $old, '<', $file ) {
push @errors, "Failed to open '$file': $!";
next FILES;
}

open(TEMP, ">temp.txt") or push @errors, "failed to create temp
file: $!";

Ditto.

These are in addition to comments by others.

Sinan

--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

.



Relevant Pages

  • [OT] Re: Media Lending Library - web based application
    ... >> (reverse each component and remove .invalid for email address) ... >> comp.lang.perl.misc guidelines on the WWW: ... snip your gaudy signature ...
    (comp.lang.perl.misc)
  • Re: How do I handle an unknown number of keys to hash?
    ... might be to insert the key into the hash with some default value but ... (remove .invalid and reverse each component for email address) ... comp.lang.perl.misc guidelines on the WWW: ...
    (comp.lang.perl.misc)
  • Re: extract variables from expression
    ... Why do you lie to the web browser? ... (remove .invalid and reverse each component for email address) ... comp.lang.perl.misc guidelines on the WWW: ...
    (comp.lang.perl.misc)
  • Re: Prematch ($`) and the m//g modifier
    ... in order to preserve the begin and end markings. ... (reverse each component and remove .invalid for email address) ... comp.lang.perl.misc guidelines on the WWW: ...
    (comp.lang.perl.misc)
  • Re: MIME::Lite send one email in for loop
    ... >>script that we can run just by cutting and pasting into an editor. ... you seemed to be using stat incorrectly. ... It does not look like you read the guidelines. ... ..\test1.jpg not sent: Failed to connect to mail server: Invalid argument ...
    (comp.lang.perl.misc)