http://www.perlmonks.org?node_id=1026352


in reply to Re: Generic Data Collection
in thread Generic Data Collection

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.