Hi,
The reason for the topic tilte is because I'l be asking various questions in the same thread over a period of time, easier then making a million threads!
Anyway, I'm having a problem with one of my scripts.
What I want to do is read a file that the user inputs.
E.g - stats.txt will open the file.
However, what i want to do, is that if the user doesn't enter a extension of .txt it will automatically add it.
My attempt:
- Code: Select all
my $file = <STDIN>;
open(READFILE, "$file") || die "No File Found";
if ($file !~ m/.txt$/)
{
$file .= ".txt";
} else {
print "There was already a .txt filename\n";
}
my $i = 0;
while (<READFILE>)
{
$i++;
}
print ("There are " . $i . " Lines in " . $file);
close(READFILE);
However, this doesn't work. =[
Any help is greatly appreciated.