Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^3: Generic Data Collection

by Not_a_Number (Prior)
on Mar 31, 2013 at 14:22 UTC ( #1026359=note: print w/replies, xml ) Need Help??

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

I think your problem is that you're not actually creating an array. Consider:

use strict; use warnings; my @parsed; # <- Here's the array in question while ( <DATA> ) { my @wanted = ( split )[ 0, 5, 9 ]; $wanted[1] =~ s/\D//g; push @parsed, join ',', @wanted; } print "$_\n" for @parsed; __DATA__ user1 machine1 (v1.1) (flexlmserver/27000 1009), start Sat + 3/30 12:53 user2 machine2 (v1.1) (flexlmserver/27000 123), start Sat +3/30 2:45

This gives an output that seems to correspond to what you request (but whether such a datastructure is ideal depends on how you intend to subsequently use it...).

Replies are listed 'Best First'.
Re^4: Generic Data Collection
by Deep_Plaid (Acolyte) on Mar 31, 2013 at 16:03 UTC

    Thanks for the quick reply. Your code works as you described and as I requested, but I don't think I explained what I needed very well. Your code creates each series as an element in the array (each line of data is an element), but I need to be able to separate out the PID data in order to work with it. I need the user to log what user was involved, and I need the time to be able to sort the list and choose the 10 "oldest" PIDS for the day. To illustrate, here's the same data:

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

    With your code gives me the output:

    $parsed[0] = user1,1009,12:53 $parsed[1] = user2,123,2:45

    When I need something like:

    @row1 = (user1,1009,12:53) $row1[0] = user1 $row1[1] = 1009 $row1[2] = 12:53 @row2 = (user2,123,2:45) $row2[0] = user2 $row2[1] = 123 $row2[2] = 2:45

    So perhaps what I really need is a multidimensional array or a way to split up the file into a grid? My end goal is to take the oldest PIDs so I can run a command on those PID numbers. Therefore I need to associate the time with the PIDs so I can identify the ones I need. You are correct the I am not asking for the correct data construct. Any further suggestions would be greatly appreciated.

      Just push the array ref instead of a string, then you can sort.
      while ( <DATA> ) { my @wanted = ( split )[ 0, 5, 9 ]; $wanted[1] =~ s/\D//g; $wanted[2] = sprintf "%05s",$wanted[2]; push @parsed, \@wanted; } print "@$_\n" for sort { $a->[2] cmp $b->[2] } @parsed;

        Excellent, POJ. This works well. I need to piece through your code to understand exactly what is doing, but I wondered if you could expand on this approach to help me in my next step. I need to identify the ten oldest PIDS and then them through another command. For simplicity, I'll just select the 2 oldest for this example. Once I identify those PIDS, I need to run the command:

        lmutil lmremove -h $PRODUCT $flexlmserver 27000 $PID[x]

        Where $PIDx would be the two oldest (or whatever # I want to select) PIDS. I'm sure this can be done using your approach, but I have no idea of the syntax. Thanks so much for your time.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1026359]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2021-10-26 13:10 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.