I decided not to be as thorough as above, but that was good info for me to keep squirelled away. I did couple google searches and ran across Getopt and did the following:
use Utils;
use Getopt::Long;
my $conf_file = '';
GetOptions ('conf=s' => \$conf_file);
if ( length($conf_file) == 0)
{
print "\nUsage: loadSMSC -conf=/path/to/config.properties\n";
exit;
}
%props = getProperties("$conf_file");
$node_name = $props{"node"};
$machine = $props{"machine"};
$username = $props{"username"};
$passwd = $props{"passwd"};
$directory = $props{"directory"};
$localpath = $props{"localpath"};
$log_name = $props{"log.name"};
$numRows = $props{"rows"};
getProperties is in Utils.pm and goes a little something like:
sub getProperties($)
{
my ($propfile) = @_;
my (%props); # Return value: a hash of property values.
my ($ln,$name,$value,@nv);
open(PROPFILE,"$propfile") or die "Unable to open $propfile";
while ($ln = <PROPFILE>)
{
chomp $ln;
$ln =~ s/#(.*$)//; # Remove line comments in the properties
+ file.
@nv = split /s*=/,$ln,2;
$value = pop @nv;
$value =~ s/^\s*=?\s*//;
$value =~ s/\s*$//;
$name = pop @nv;
$name =~ s/^\s*//;
$name =~ s/\s*$//;
if ($name ne "")
{
$props{$name} = $value;
}
}
close(PROPFILE);
return %props;
}
sub dumpProperties
{
my (%props) = @_;
foreach $prop (keys %props)
{
#print "\t\t$prop\n";
print "\t\t$prop:$props{$prop}\n";
}
1;
}
Thanks for the input!
Jimbus
A sniveling Jimbus advices, "Never moon a werewolf!"
|