in reply to Remembering values from multiple condition 'if'

When in doubt, rethink code structure... ;)

for my $file ( qw/ file1 file2 file3 file4 ) { if( -e $file ) { unlink($file) || print STDERR "error unlinking $file: $!\n"; } }

Replies are listed 'Best First'.
•Re: Re: Remembering values from multiple condition 'if'
by merlyn (Sage) on Jul 02, 2002 at 14:15 UTC
    There's really no point in testing to see if an unlink might succeed before attempting it. Just do the unlink:
    unlink qw/ file1 file2 file3 file4 /;
    Although your way is cooler if you want clean error messages if something goes wrong.

    -- Randal L. Schwartz, Perl hacker