[Chicago-talk] OK< *real* stupid Q time...

Mike Pastore mike at oobak.org
Tue Sep 16 18:47:30 CDT 2003


Hi Walter,

Have you ever visited the site perlmonks.org? It is a Perl forum
dedicated to answering questions just like these. You may have better
luck there. I'm new to the list but I don't believe it's meant for this
type of discussion.

Don't you mean to be testing input files, not output files? If the output
file can't be opened, you definitely want to "die". Also, if you're using
the -p or -n switch, you don't need to explicitly open input files. It
will read them from the command line automatically. And if a file is
missing, perl will output its own error message:

    $ ./walter.pl -o=file3 file1 file2 file4
    Can't open file4: No such file or directory, <> line 10.

Regards,

Mike

On Tue, 16 Sep 2003 17:09:29 -0500, "Walter Torres" <walter at torres.ws>
said:
> OK, I have this piece that opens a file or dies trying with a little
> error
> sent to STOUT.
> 
>    open( TEMP, ">>./$outFile ")
>       or die "No Way! \n$!\n$outFile \n";
> 
> But, I have this in a loop of file names to parse.
> 
> So I need to have this try and open that file, and if it fails, send a
> call
> to a function (that logs stuff) and tell the FOR loop to go on to the
> next
> in the list.
> 
> I figure that there must be a way to test if a file can be opened before
> actually opening it and then have conditionals around that....
> 
>    if (! open $outFile)
>    {
>       &to_log ("$outFile Error: $errCode");
>       continue;
>    }
> 
> I know I've done this before, but my brain dead head can't remember this,
> nor have I been able to find any URL via GOGGLE that helps me.
> 
> Thanks for your patience through these basic questions.
> 
> That's what I get for not working in Perl for way too long!
> 
> Walter
> 
> 
> 
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk



More information about the Chicago-talk mailing list