On Fri, 10 Dec 2004 21:07:45 +0100, M. Duijkers wrote:
> #!perl -w
> do
> {
> print "Enter filename or QUIT to stop: ";
> $filename = <STDIN>;
> chomp $filename;
> if ($filename ne "QUIT")
> {
> if (! -e $filename)
> {
> print "file does not exist\n";
> last;
> }
> if (-r $filename)
> {
> print "file is readable \n";
> }
> else
> {
> print "file is NOT readable \n";
> }
> if (-w $filename)
> {
> print "file is writeable\n";
> }
> else
> {
> print "file is NOT writeable \n";
> }
> if (-x $filename)
> {
> print "file is executable\n";
> }
> else
> {
> print "file is NOT excecuteable \n";
> }
> }
> else
> {
> exit 0;
> }
> }while ($filename ne "QUIT")
Here is my suggestion for a solution;
#!/usr/bin/perl
#
use strict;
use warnings;
while ( <DATA> ) {
chomp;
last if ( $_ eq 'QUIT' );
if ( -e ) {
my %status = ('readable' => -r,
'writeable' => -w,
'executable' => -x);
my @status = map { ( $status{$_} ) ? $_ : 'NOT ' . $_ } keys %status;
print "'$_' is " . join( ', ', @status ) . "\n";
}
else {
print "'$_' doesn't exist!\n";
}
}
--
Tore Aursand <>
"First, God created idiots. That was just for practice. Then He created
school boards." (Mark Twain)
|