[Chicago-talk] OPEN() conditional

tiger peng tigerpeng2001 at yahoo.com
Thu Jun 30 12:12:41 PDT 2011


yes ?: works
> ls *.log

sqlnet.log
> perl -le '
open(F, (-f "asqlnet.log") ? "<asqlnet.log": "<sqlnet.log")
 or die "oops $!"'
> perl -le '
open(F, (-f "asqlnet.log") ? "<asqlnet.log": "<bsqlnet.log")
 or die "oops $!"'
oops No such file or directory at -e line 2.




________________________________
From: tiger peng <tigerpeng2001 at yahoo.com>
To: Chicago.pm chatter <chicago-talk at pm.org>
Sent: Thursday, June 30, 2011 2:05 PM
Subject: Re: [Chicago-talk] OPEN() conditional


if (-f '/blah/blah') {open F, "</blah/blab"} else { open F, "</blab"}. 


maybe ?: will work too.



________________________________
From: Richard Reina <richard at rushlogistics.com>
To: chicago-talk at pm.org
Sent: Thursday, June 30, 2011 1:46 PM
Subject: [Chicago-talk] OPEN() conditional

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



_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20110630/26256fac/attachment.html>


More information about the Chicago-talk mailing list