Results 1 to 4 of 4

Thread: Need some help

  1. #1
    Join Date
    May 2004
    Posts
    105

    Unanswered: Need some help

    I am collecting hardware information using WMI but I need to load it to my database. There are a few table that I needed to insert this data to but I need to do it without having to hardcode it entirely.

    The data is in a hash: my $hwinfo = $hostobj->get_hwinfo();

    Where the data looks like this:
    key | data
    -----------------------------
    hw_CurrentClockSpeed 2392
    hw_SerialNumber 11111ab

    But, now I need to disseminate it to the appropriate tables. For example, hw_SerialNumber data needs to be put into the Host table under the SerialNumber column and hw_CurrentClockSpeed data needs to go into the CPU table in the ClockSpeed column. Anyone have any ideas on how I should go about this?

    Thanks.
    Last edited by lauramccord; 08-03-04 at 16:59.

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    If you know the keys and the columns you can use a hash:
    Code:
    my %hash = (hw_CurrentClockSpeed => 'ClockSpeed',
          hw_SerialNumber => 'SerialNumber',
          );
    
    my $key = 'hw_CurrentClockSpeed'; # as an example... you have to adapt it to your needs
    my $sql = 'INSERT INTO table('.$hash{$key}.') values('.$hwinfo->{$key.');';
    board.perl-community.de - The German Perl-Community

  3. #3
    Join Date
    May 2004
    Posts
    105
    I need to differentiate between each piece of data and what table it needs to go into.

    If I had a hash that contained a key that indicates the table name how would I put the remaining information like hw_CurrentClockSpeed => '2392'? So there are three pieces of information that I need to store.

    Is there a way to do this:
    %hash=(
    #Host is the name of a table
    "Host" => another hash that contains hw_CurrentClockSpeed => 'ClockSpeed'
    "CPU" => another hash.....
    );

  4. #4
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    I would make a Hash like this one:
    Code:
    my %hash = (hw_CurrentClockSpeed => ['Host','ClockSpeed'],
           hw_SerialNumber => ['table_name','col_name'],
           ...
           );
    
    my $key = 'hw_CurrentClockSpeed'; # as an example... 
    my $sql = 'INSERT INTO '.$hash{$key}->[0].'('.$hash{$key}->[1].') values('.$hwinfo->{$key.');';
    So you would have 2 Hashes:
    1) The Hash(ref) hwinfo which contains all values wanted to be added into the database
    2) The Hash %hash which contains all information about the table and the columnname where the values have to be stored to...
    Last edited by reneeb; 08-05-04 at 02:49.
    board.perl-community.de - The German Perl-Community

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •