
BillKSmith
Veteran
Oct 20, 2013, 1:08 PM
Post #2 of 12
(2325 views)
|
Re: [CodingNub] Help with Regex
[In reply to]
|
Can't Post
|
|
You do not seem to know the meaning of the $ or @ at the beginning of a perl variable. Please read the perl documentation 'perldata'. (At you command line, type perldoc perldata) Your external function 'dsmadmc' appears to be a database interface. You probably can (and should) do the whole job in perl using the module DBI as your db interface. Numbers can come in a surprisingly large number of formats. The safest way to match all numbers and nothing else is to use the module Regex::Common. It is actually easier to match both your numbers with one Regex than it is to do them separately. I divided up your long command line to fit the page. The string sent to the shell should be exactly the same as yours.
#!/usr/bin/perl use strict; use warnings; #use List::Util qw(max); use Regexp::Common; use Readonly; Readonly::Scalar my $NUMBER => qr/$RE{num}{real}/; Readonly::Scalar my $SELECT => q["SELECT] .q[ Sum(VOLUMES.EST_CAPACITY_MB),] .q[ Sum(VOLUMES.EST_CAPACITY_MB*volumes.pct_utilized/100)] .q[ FROM VOLUMES VOLUMES WHERE (VOLUMES.DEVCLASS_NAME='DISK')"] ; my $rundsm = `dsmadmc -id=reports -pa=reports $SELECT | grep " "`; my ($totalspace, $diskused) = $rundsm =~ /($NUMBER).+($NUMBER)/; print "Message: Total Disk Space available\n", "Statistic: $totalspace\n"; print "Message: Actual Disk in Use\n", "Statistic: $diskused\n"; exit 0; Good Luck, Bill
|