[Chicago-talk] OPEN() conditional

Shawn Carroll shawn.c.carroll at gmail.com
Thu Jun 30 12:05:38 PDT 2011


Instead of a readdir or even attempting the open the file, just test
for it's existance ala:

my $file = -e $file1Path ? $file1Path: -e $file2Path ? $file2Path: die
'neither file avail';
open (my $FH, '<', $file) or die ' Cannot open $file: $!' ;

shawn.c.carroll at gmail.com
Perl Programmer
Soccer Referee



On Thu, Jun 30, 2011 at 13:46, Richard Reina <richard at rushlogistics.com> wrote:
> I am writing a script that among other things edits a file.  The file can be in one of two places (directories) so if the first open does not work I want it to try the open of the file in the alternative directory.  I know how to do open(F, "</blah/blah") || die or open(F, "</lbal") || warn; but I don't want the program to die but to try another directory.  Is there a way to do open() conditionals or do I need to use readdir first to see if the file exists?
>
> Thanks,
>
> Richard
> --
> Richard Reina
> Rush Logistics, Inc.
> Watch our 3 minute movie:
> http://www.rushlogistics.com/movie
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>


More information about the Chicago-talk mailing list