in reply to Reduce Redundant Repetition
There are a number of ways to reduce some of this. The easiest way to get rid of the if's is probably something like:
$contimeout = $opt_contimeout || 3;Another simple way of setting defaults is to set them up before using Getopt::Long:
#!/usr/bin/perl -w use strict; use Getopt::Long; my ($lines, $cols) = (5, 16); GetOptions ('line=s' => \$lines, 'col=s' => \$cols); print "Lines: $lines Cols: $cols\n";
A very simple example I know, but it illustrates the point :)
Update: jcwren pointed out that I failed to mention this has a potential failure if you use '||' - if you want to set a value to '0', you won't be able to unless the default is also '0'. I advise pre-setting the defaults, and then letting the user override them - much simpler :) Thanks, jcwren.
|
|---|