A few things:
Chomp changes the string, and returns the number of character chomped. After that input line, chomp $master_testplan_conf
is most likely to 1
, so you're comparing 1
to the null string.
You can do it this way:
chomp ( $master_testplan_conf = <> );
if you want to do everything on a single line.
That will read your input and do the chomp in one step. Also, the <>
operator will take files from the command line and <>
will be the first line of the first file on the command line. If you don't want to do that, use <STDIN>
:
chomp ( $master_testplan_conf = <STDIN> );
You may want to sanitize your user's input. I would at least remove any leading and ending blanks:
$master_testplan_conf =~ s/^\s*(.*?)\s*$/$1/; # Oh, I wish there was a "trim" command!
This way, if the user accidentally presses spacebar a few times, you don't pick up the spaces. You also may want to test for the file's existence too:
if ( not -f $master_testplan_conf ) {
die qq(File "$master_testplan_conf" not found);
}
I also recommend to use:
if ( not defined $master_testplan_conf or $master_testplan_conf eq "" ) {
for your if
statement. This will test whether $master_test_conf
is actually defined and not merely a null string. Right now, this doesn't matter since the user has to at least enter a \n
. The $master_testplan_conf
stroll will never be null.
However, it may matter if you decide to use Getopt::Long.