in reply to Re: scalar dereferencing
in thread scalar dereferencing
thank you to both of you for guiding and enlightning replies.
I have learned quite a bit through this, and have found the thrill of my first real hash.
Here is how the code currently stands (as always, a work in progress):
#!/usr/bin/perl -w use strict; ## usage information # $0 UPSNAME HOSTNAME DATAPOINT # where DATAPOINT can be any of # UTILITY - the number VAC utility power is providing # LOADPCT - the percentage of the maximum load # BATTPCT - percent of total battery charge available # RUNTIME - approx. number of minutes of battery life # note that DATAPOINTs *must* be specified in all caps my ($key, $val, %upsdata); foreach (`/usr/local/bin/upsc $ARGV[0]\@$ARGV[1]`) { ($key, $val) = /(\w+):\s(.*)(\n)?/; $upsdata{$key} = $val; }; if ($ARGV[2]) { print "$upsdata{$ARGV[2]}\n"; } else { print "utility is $upsdata{UTILITY}\n"; print "loadpct is $upsdata{LOADPCT}\n"; print "battpct is $upsdata{BATTPCT}\n"; print "runtime is $upsdata{RUNTIME}\n"; };
|
|---|