I have another question about this code. Today was I was able to test this live and I have discovered there are cases where my data is not aligned correctly. I have been able to use a regex to address the problem, but the data set I am correcting is not getting loaded into the array. Here's the code:
my $license_cmd = "lmutil lmstat -f $PRODUCT";
my @parsed;
open LICENSES, "$license_cmd |" || die "Can't execute ($license_cmd) \
+n$!\n";
while (<LICENSES>)
{
my $data_line = $_;
# Post FlexLM Version 7.0 - Find max number of licenses available
if ($data_line =~ /Total of (\d+) licenses issued/)
{ $MAX_LIC = $1; }
# Identify the lines of output that contain user license info
elsif ($data_line =~ /\, start /)
{
# Remove leading spaces from the lines
$data_line =~ s/^\s+//g;
# Remove duplicate data from the lines (web logons)
$data_line =~ tr/-//d; # Remove hyphens to remove the duplicat
+e server name
$data_line =~ s/(\b\w+\b)(\s*\1)+/$1/g; # Remove duplicate ser
+ver name
print "\n$data_line"; # <-- test results of data changes
# Load user name, PID and Start Time into array USAGE_INFO
my @USAGE_INFO = ( split)[ 0, 5, 9 ];
$USAGE_INFO[1] =~ s/\D//g;
$USAGE_INFO[2] = sprintf "%05s",$USAGE_INFO[2];
push @parsed, \@USAGE_INFO;
}
}
close LICENSES;
The problem appears to be the line:
my @USAGE_INFO = ( split )[ 0, 5, 9 ];
...is getting it's data directly from the raw data produced by the license command in the open file LICENSES. This makes sense, since I am massaging the data in $data_line. I have read up on SPLIT and array creations and have tried the following to build the @USAGE_INFO array with $data_line, but I can't seem to get it to work:
my @USAGE_INFO = ( split )[ 0, 5, 9 ], $data_line;
my @USAGE_INFO = ( split ($data_line) )[ 0, 5, 9 ];
Any further help would be greatly appreciated. Thanks!
|