perldesire has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

In Parse::Dmidecode there is a function named as keywords() which accepts the following keys,
bios
system
baseboard
chassis
processor
memory
cache
connector
slot

my @list_keywords = $dmi->keywords("slot"); //Its giving same output +for slot, processor and memory etc for my $keyword (@list_keywords) { printf("%s => %s\n", $keyword, $dmi->keyword($keyword) ); }

I could not find any difference in the output for different keywords.. $dmi->keywords("slot"), $dmi->keywords("processor") , $dmi->keywords("memory") giving mostly same output..

Kindly help me to understand the difference.

Replies are listed 'Best First'.
Re: parse dmidecode keywords
by NetWallah (Canon) on Jun 30, 2009 at 13:10 UTC
    The "keywords" method seems to be coded to ignore the parameter, causing the behaviour you see:
    sub keywords { my $self = shift; croak 'Not called as a method by parent object' unless ref $self && UNIVERSAL::isa($self, __PACKAGE__); my %keywords; my $stor = $objstore->{_refaddr($self)}; for my $handle (@{$stor->{parsed}->{handles}}) { for my $keyword ($handle->keywords) { $keywords{$keyword} = 1; } } return sort(keys(%keywords)); }
    Since the documentation is not explicit about what it SHOULD do, it is not technically a bug. But I would call it a poor example.

    I would recommend sub-classing it to do what you ned, and try to contact the author.

         Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)

Re: parse dmidecode keywords
by Khen1950fx (Canon) on Jun 30, 2009 at 18:22 UTC
    I figured that it had to be a simple mistake---Ah!

    $keyword, $decoder->keyword($keywords) );

    solved the problem:

    #!/usr/local/bin/perl use strict; use warnings; use Parse::DMIDecode; my $decoder = Parse::DMIDecode->new( dmidecode => "/usr/sbin/dmidecode", nowarnings => 1, ); $decoder->probe; my @keywords = $decoder->keywords; for my $keyword (@keywords) { printf("%s => %s\n", $keyword, $decoder->keyword($keyword) ); }
    Update: It's been awhile since I used Parse::DMIDecode. I remembered that the "mistake" is not a mistake. In other words, what you are seeing is exactly what Parse::DMIDecode should be doing. You are entering "slot", but "slot" is not a keyword but a "type". A "keyword" is a "string". If you enter a type, dmidecode will return a list of all valid keywords, which is what is happening. For example, a keyword would be something like system-version, processor-manufacturer, etc. Dmidecode has a good man page. Be sure to check it out.

    Update: Just a little script to look at the "slot" type:

    #!/usr/bin/perl use strict; use warnings; use Parse::DMIDecode; my $decoder = Parse::DMIDecode->new( dmidecode => '/usr/sbin/dmidecode', nowarnings => 1, ); $decoder->probe; printf("System: %s => %s %s %s %s\n", $decoder->keyword("slot-current-usage"), $decoder->keyword("slot-designation"), $decoder->keyword("slot-id"), $decoder->keyword("slot-length"), $decoder->keyword("slot-type"), ); my $total_structures = $decoder->structures; printf("Structures: %s\n", $decoder->structures($total_structures), );

    I added $decoder->structures($total_structures). It'll tell how many "types" there are. I got 40---numbered starting at 0 thru 39.