O'Reilly logo

Learning Perl/Tk by Nancy Walsh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

16.20. Parsing Command-Line Options

In the Unix world, it is standard practice to specify command-line options when you are invoking an application, especially a graphical program. Starting your program as myscript -geometry "80x40" would not be unusual. To have Perl/Tk automatically parse and apply these command-line options for you, just call CmdLine immediately after you create your MainWindow.

$mw->CmdLine();

In Tk4, if you want to have CmdLine stop processing command-line arguments and leave some for you to deal with, add a double dash (--) before the arguments you want it to leave for you; for instance, myscript -geometry "80x40" -- -myopt.

In Tk8, the processing of options will stop when the first unknown option is found.

Another way to deal with command-line options is to use the Perl Getopts modules. Take a look in Programming Perl (O'Reilly, 1997) to find out how to use the methods available in Getopts. The methods inside Getopts don't handle the options for you; it just puts them in a structure that's easier to deal with.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required