Questions about this topic? Sign up to ask in the talk tab.
Perl/Basics/User Input/Command Line/Getopt::Long/Analysis
From NetSec
Revision as of 03:14, 16 July 2012 by AlizaLorenzo (Talk | contribs) (Created page with "The '''GetOptions()''' function receives message formats and '''references''' for variable assignment. You can execute the script as follows: perl script.pl --message "hello" -...")
The GetOptions() function receives message formats and references for variable assignment. You can execute the script as follows:
perl script.pl --message "hello" --boolean perl script.pl --message "hello"
In the above example, we see the line:
GetOptions('message=s' => \$message, 'boolean' => \$boolean);
You can see from the execution pattern above that the GetOptions() function provides an interface for the "double-dash" style command line arguments. The GetOptions() function receives a hash. The =s after message designates that the --message parameter receives a string data type. An =i will change it to integer. Simple no = will set the flag to a boolean; similar to an argument without a colon in Getopt::Std. Notice each variable is passed as a reference.