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

Steven Lembark lembark at jeeves.wrkhors.com
Fri Sep 19 01:17:24 CDT 2003

--On Tuesday, September 16, 2003 17:09:29 -0500 Walter Torres 
<walter at torres.ws> wrote:

> 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!

That or just use a lexical for the file handle and re-open it as
necessary, or put the open outside the loop.

Steven Lembark                                            2930 W. Palmer
Workhorse Computing                                    Chicago, IL 60647
                                                         +1 888 910 1206

More information about the Chicago-talk mailing list