Parse:...amples(3pm)
π Parse::DMIDecode::Examples(3pm)
okay bestie, welcome to the User Contributed Perl Documentation corner of the universe π this one lives in section 3pm (that's "perl module" to the uninitiated, iykyk), and it's literally just a lil scrapbook of examples. no cap.
β¨ NAME β¨
Parse::DMIDecode::Examples β examples using Parse::DMIDecode::Examples. yes, the page is describing itself with itself. main character energy fr fr, we love a self-referential icon π
πΈ EXAMPLES πΈ
π¦ Example 1: Find the Number of Physical CPUs
okay so this is the whole vibe: you spin up a Parse::DMIDecode object, you probe it, you walk every handle in the processor group, and you count the ones that are actually real physical CPUs and not some unpopulated ghost socket situation π
use strict;
use Parse::DMIDecode qw();
my $dmi = Parse::DMIDecode->new( nowarnings => 1 );
$dmi->probe;
my $physical_cpus = 0;
for my $handle ($dmi->get_handles(group => "processor")) {
my $type = ($handle->keyword("processor-type") or "");
next unless $type =~ /Central Processor/i;
# Check the status of the cpu
my $status = ($handle->keyword("processor-status") or "");
if ($status !~ /Unpopulated/i) {
$physical_cpus++;
}
}
printf("There %s %d physical %s in this machine.\n",
($physical_cpus == 1 ? "is" : "are"),
$physical_cpus,
($physical_cpus == 1 ? "CPU" : "CPUs"),
);
a few lil notes on what's happening here, bestie π«Ά
use strict;anduse Parse::DMIDecode qw();β pulling in the module with an empty import list, so nothing gets dumped into your namespace. respectful. iconic.Parse::DMIDecode->new( nowarnings => 1 )β constructing the object, and asking it to keep the warnings to itself.$dmi->probe;β go get the DMI data. no probe, no data, no vibes.$dmi->get_handles(group => "processor")β grabbing every handle in theprocessorgroup, then looping over them one by one.$handle->keyword("processor-type")β pulling theprocessor-typekeyword out of each handle. theor ""is there so a missing keyword becomes an empty string instead of a sad littleundefπnext unless $type =~ /Central Processor/i;β skipping anything that isn't aCentral Processor(case-insensitive, we're not out here being picky).$handle->keyword("processor-status")β same deal for theprocessor-statuskeyword, again with theor ""safety net.if ($status !~ /Unpopulated/i)β the actual filter. if the status does not matchUnpopulated, it's a real, populated CPU, so$physical_cpus++.- the
printfβ prints a sentence that grammatically adapts to the count. one CPU gets "There is 1 physical CPU", everything else gets "There are N physical CPUs". pluralisation ate, honestly π₯
the # Check the status of the cpu comment is part of the original code, so it stays exactly where it is. we do not touch the artifacts β¨
π COPYRIGHT π
Copyright 2007 Nicola Worthington.
This software is licensed under The Apache Software License, Version 2.0.
<http://www.apache.org/licenses/LICENSE-2.0>
and that's the whole page, bestie π this was shipped with perl v5.36.0 and dated 2022-10-13, and it's filed under Parse:...amples(3pm). go count some CPUs, you absolute legend πβ¨π
π¦ where this page comes from
- ubuntu noble: libparse-dmidecode-perl 0.03-4 Β· Apache-2.0
- ubuntu resolute: libparse-dmidecode-perl 0.03-4 Β· Apache-2.0
- ubuntu stonking: libparse-dmidecode-perl 0.03-4 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms