How to Use Perl CPU Info?

Asked By 0 points N/A Posted on -

Hi Everyone,

I want to know the importance of Perl CPU info and how to use it?

I am new to Perl and I am not sure how to use it in my codes.

If you can provide tutorials and sample codes, it will be very useful.

Thank you very much.

Best Answer by Cannon Timothy
Answered By 0 points N/A #183629

How to Use Perl CPU Info?


This Perl script determine's information about the installed OS, computer name, processor , RAM , hard-drives, and computer network settings.

Perl WinInfo. pulls > output. txt

This will save the output of the script to a file called output.txt.

use Win32;
use Win32::SystemInfo;
use Win32::DriveInfo;
use Win32::IPConfig;
use strict;
use warnings;

print "OS Informationn";
my $computer=Win32::NodeName();
print "Computer name :$computern";

My $domain=Win32:: DomainName ();
Print "This Computer is a member of the $domain domain/workgroupn";

my $OS=Win32::GetOSDisplayName();
Print "The OS is $OSn";

my $fs=Win32::FsType();
print "The filesytem is $fsn";

my $user=Win32::LoginName();
print "Current user is $usern";

my $admin=Win32::IsAdminUser();
    print "$user is running this script as adminnnn";
    print "$user is not running this script as adminnnn";

print "Processor Information and RAM Informationn";
my %processor;
for (my $i=0;$i<$processor{NumProcessors};$i++) {
    print "Processor$in";
    print "Processor Name: " . $processor{"Processor$i"}{ProcessorName} . "n";
    print "Processor Info: " . $processor{"Processor$i"}{Identifier} . "n";
    print "Processor Speed: " . $processor{"Processor$i"}{MHZ} . "MHznn"; 

my %memory;
Win32::SystemInfo::MemoryStatus(%memory, 'GB');
print "The computer has $memory{TotalPhys} GB of RAMnnn";

my %dtypes=(0 => "Undetermined",
1 => "Does Not Exist",
2 => "Removable",
3 => "Hard drive",
4 => "Network",
5 => "CDROM",
6 => "RAM Disk");

print "Drive Informationn";
my @drives = Win32::DriveInfo::DrivesInUse();
foreach my $drive (@drives){
    my $type=Win32::DriveInfo::DriveType($drive);
    print "Drive $drive is a $dtypes{$type}n";

print "nnNetwork Information";
my $ipconfig = Win32::IPConfig->new($computer)
        or die "Unable to connect to $computern";
foreach my $adapter ($ipconfig->get_adapters) {
    print "nAdapter '", $adapter->get_name, "':n";

    print "Description=", $adapter->get_description, "n";

    print "DHCP enabled=",
    $adapter->is_dhcp_enabled ? "Yes" : "No", "n";

    my @ipaddresses = $adapter->get_ipaddresses;
    print "IP [email protected] (", scalar @ipaddresses, ")n";

    my @subnet_masks = $adapter->get_subnet_masks;
    print "subnet [email protected]_masks (", scalar @subnet_masks, ")n";

    my @gateways = $adapter->get_gateways;
    print "[email protected] (", scalar @gateways, ")n";

    print "domain=", $adapter->get_domain, "n";

    my @dns = $adapter->get_dns;
    print "[email protected] (", scalar @dns, ")n";

    my @wins = $adapter->get_wins;
    print "[email protected] (", scalar @wins, ")n";

Best Answer
Best Answer
Answered By 0 points N/A #183631

How to Use Perl CPU Info?


Hi Judith,

Perl is a general purpose scripting language (computer language) that is popular for its ability to make easy things easy and for difficult things possible. Among the scripting languages that are used in writing scripts using CGI, Perl is the most popular one. There are about 3000 Perl CGI scripts as compared to that of C/C++ which only has about 220 scripts.

Although Perl may not be the best option for developing apps with a GUI, Perl can still be used to develop robust applications that require a lot of database management and a lot text manipulation. It also comes very handy in the gathering or extraction of useful information from complex structured databases.

What's great about Perl is that it allows you to accomplish a lot by writing only very little and unlike other programming languages, it helps you get rid of the "clutter" that are usually involved in other scripting languages. 

Attached are just some basic example codes utilizing Perl.

I hope you'll have more fun and satisfaction in learning more about the language.

Login/Register to Answer

Related Questions