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!


In reply to Re^8: Generic Data Collection by Deep_Plaid
in thread Generic Data Collection by Deep_Plaid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.