Here's a snippet of the code I am working with:

$flexlm_cmd = "lmutil lmstat -f ${product}"; #other junk $license_cmd = "$flexlm_cmd"; open LICENSES, "$license_cmd |" || die "Can't execute ($license_cmd +) \n$!\n"; while (<LICENSES>) { $data_line = $_; # my @data = split; #print if grep $_ > 99, @data[1..$#data]; if ($data_line =~ /27000 (\d+)/) { @license_pid = $1; } if ($data_line =~ /Total of (\d+) licenses issued/) { $max_licenses = $1; } elsif ($data_line =~ /Total of (\d+) licenses in use/) { $licenses_used = $1; } elsif ($data_line =~ /minutes \(at /) { ($JUNK, $user, $JUNK) = split (/\s+/, $data_line); $user_list ="$user,$user_list"; }

and here is the line that is giving me trouble. I've tried loading the data into an array (string shown here), but it's not working. I would prefer to put it in an array (more further down)

elsif ($data_line =~ /\, start /) { $data_line =~ s/^\s+//g; print $data_line; ($user, $IP, $machine, $VER, $JUNK, $PID, $JUNK, $SDAY, $SDATE +, $start_time) = split (/\ /, $data_line); $user_list ="$user,$user_list"; $start_list ="$start_time,$start_list"; $licenses_used++; } } close LICENSES;

Here's a snippet of the output $flexlm_cmd command output:

user1 192.168.1.1 machine1 (v1.1) (flexlmserver/27000 1009), start Sat + 3/30 12:53 user2 192.168.1.2 machine2 (v1.1) (flexlmserver/27000 123), start Sat +3/30 2:45

The code above works fine but not on multiple lines. The variables only end up with the values from the last line (I tried using arrays instead and that didn't work either). My objective is to build arrays where I have paired up the user name (first block of characters in the line), the process ID (the sixth block of characters, and I have to trim the ")"), and the time (the last block of characters). So from the above example, the output of the arrays would be:

array1 = (user1,1009,12:53) array2 = (user2,123,2:45)

I need an association between the PID and the time, so I can sort them by time, then perform further processing on the PIDs that are the oldest. That should be easy, but I can't seem to load up the arrays as shown above (if that is indeed the best way to do this). Again, my apologies for the simple question. I am under time pressure to get this done and all the tutorials I have read on arrays, regex and splitting have not all added together for a solution, so I thought I'd seek the wisdom of the monks. Thank you.


In reply to Re:^2 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.