I have written a perl package Parsepw which will parse the configuration file and returns the userid and password from config file to main script.
My module looks like this:
package Parsepw;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT_OK = qw(parse_config_file);
sub parse_config_file {
...
#reads the config file, if not found print error message here else using regex extract user and password line
...
if ( $user && $ciphertext ){
return ( $user, $ciphertext );
}
}
1;
Below is my main script:
...
use Parsepw;
my ($user, $passwd) = Parsepw::parse_config_file();
print "$user, $passwd\n";
I am able to retrieve user and passwd in positive test scenario, but in negative test case how can I handle it.
If suppose parse_config_file subroutine couldn't able to parse the configuration file in the module how can I throw an error/warning to my main script? Since the return value I have is $user, $passwd, how can I have the error/warning message?
Without using package everything works fine if I put all the code in single script. I was trying to write separate package for first time.