welshhuw
03-16-2009, 09:16 PM
Hi,
In my program I need to check if an argument (text file) has been provided, and if not, I need the program to ask the user for a filename via the keyboard.
I have written the code below and it almost works!
The problem I am getting is that if an argument HAS been provided, the if clause works correctly. (And asks the user for input via STDIN)
But, if an argument HAS NOT been provided, the if clause prints to the screen and runs the else clause. (Without letting the user enter data)
Maybe if you copy and paste this code you can see for yourself what i mean.
Any help would be greatly appreciated?
Thanks in advance.
if($#ARGV== -1)
{
print("Enter a Filename Please: ");
$filename = <STDIN>;
chomp($filename);
}
else
{
$filename = $ARGV[0];
}
In my program I need to check if an argument (text file) has been provided, and if not, I need the program to ask the user for a filename via the keyboard.
I have written the code below and it almost works!
The problem I am getting is that if an argument HAS been provided, the if clause works correctly. (And asks the user for input via STDIN)
But, if an argument HAS NOT been provided, the if clause prints to the screen and runs the else clause. (Without letting the user enter data)
Maybe if you copy and paste this code you can see for yourself what i mean.
Any help would be greatly appreciated?
Thanks in advance.
if($#ARGV== -1)
{
print("Enter a Filename Please: ");
$filename = <STDIN>;
chomp($filename);
}
else
{
$filename = $ARGV[0];
}