M
M. Duijkers
Heya... currently working my way through the book "learning perl". Just
having trouble with control structures.I want to do smth simple but can only
come with a bulky and ugly answer. What I want my program to do is "recieve
filenames from stdin ina loop, and when you recieve the string "QUIT" then
quit.
This is how I did it, but I just KNOW there is a better and easier way for
such a common task. Any sugs really appriciated
Mike.
#!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")
having trouble with control structures.I want to do smth simple but can only
come with a bulky and ugly answer. What I want my program to do is "recieve
filenames from stdin ina loop, and when you recieve the string "QUIT" then
quit.
This is how I did it, but I just KNOW there is a better and easier way for
such a common task. Any sugs really appriciated
Mike.
#!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")