Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a situation to monitor the non-existance of a file! An existance is a bad thing. A non-existance is good. What would be the simplest way to id the non-existance of a file. (IBM AIX) Thanx. Bill

Replies are listed 'Best First'.
Re: File Check, Not.
by jhourcle (Prior) on Jul 21, 2005 at 18:01 UTC
    if (-e $file) { # do something (it exists) } else { # do something else (it doesn't exist) }

    See -X

    update: clearly marked that this deals with it existing.

Re: File Check, Not.
by Fletch (Bishop) on Jul 21, 2005 at 18:10 UTC

    Anonymous, I'd like you to meet Race. Race Condition.

    Be sure you're not trying to use -e or stat to avoid doing proper file locking. Check out perldoc -f flock and perldoc perlopentut otherwise.

    --
    We're looking for people in ATL

Re: File Check, Not.
by gam3 (Curate) on Jul 21, 2005 at 18:03 UTC
    if (!-e 'filename') { print "File NOT\n"); }
    -- gam3
    A picture is worth a thousand words, but takes 200K.
Re: File Check, Not.
by friedo (Prior) on Jul 21, 2005 at 18:08 UTC
    Or, on a more English-friendly note,

    unless( -e $file ) { # something good } else { # something bad }
Re: File Check, Not.
by Codon (Friar) on Jul 21, 2005 at 23:47 UTC
    I like terse:
    $status = (-e $file) ? 'bad' : 'good';

    Ivan Heffner
    Sr. Software Engineer, DAS Lead
    WhitePages.com, Inc.