I need to do the following:
Print "User please enter the age, sex, blah_blah" > $age>$sex>$blah_blah;
print "the current user stats are- age = $age, sex = $sex";
my $rand;
if ($blah_blah > $rand)
{
do something
}
else
{
something else
}
Can someone help me with to take inputs from the user and then be able to use that value in the script?
I also want to be able to run this script as:
perl script1 -age -sex -blah_blah
By that I mean instead of asking the user to provide these values can I simply type these in the command line and can my script still use these as above?
Is this possible? If so, can I also add -help
i.e. perl script1 -help
and if this could print out some comments from the script?
Try this for command line options and help ..run as..in place of my params put age,sex,address whatever you want.
perl test.pl -pass 'abcd' -cmd 'abcd' -path 'paths' -value 'testde'
The Perl module IO::Prompt::Tiny is useful for prompting with a prompt message, accepting input portably, or accepting default values if it detects a non-interactive runtime.
Combine this with Getopt::Long to accept command line inputs.
Your program might check for the definedness of the Getopt::Long options, and for each one that hasn't been supplied on the command line, invoke
prompt()
.Usage info and documentation are made trivial by the Perl module Pod::Usage.
Here's an example:
Getopt::Long and Pod::Usage are core Perl modules; they ship with every Perl distribution, so you should already have them. IO::Prompt::Tiny is on CPAN, and although it has a few non-core build dependencies, its runtime dependencies are core-only, and pretty light-weight.