I trying to learn the art of Creating a Package (module)
So I want to make sure everything works the way it should so I enabled stricts and warnings.

Everytime I run my Code I end up with the Following errors:

Use of uninitialized value in string ne at C:/Perl/lib/Services.pm line 78.
Use of uninitialized value in exists at C:/Perl/lib/Services.pm line 67.

Could you tell me what I am doing wrong Or how I can Clean it up.

package Services; require Exporter; use Win32::OLE qw( in ); use strict; use warnings; require DBD::mysql; my @ISA = qw(Exporter); =head1 NAME Services - Connects to Servers to get Services and Usernames =head1 SYNOPSIS use Services; Services::UpdateDB; =head1 DESCRIPTION This module provides a list of all services running on a Server/PC and + the User Account That it is running under. The code begins after the "cut" statement. =cut my @EXPORT = qw( UpdateDB ); sub TimeClock { my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $da +yOfWeek, $dayOfYear, $daylightSavings) = localtime(); my $year = 1900 + $yearOffset; my $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $month +s[$month] $dayOfMonth, $year"; return $theTime } sub Services::UpdateDB { my $Machine = shift; my $IP = shift; my $Logfile = shift || "Null"; my $DSN = 'driver={SQL Server};Server=10.10.0.31;database=Services +_Info;uid=Nope;pwd=WhatEver;'; my $ServiceQuery = "Select Service from dbo.Services"; my $Class = "CIM_Service"; my %Service_Info; my $DataHandle = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errs +tr\n"; my $StatementHandle = $DataHandle->prepare("SELECT * FROM dbo.Serv +ices where ServerName = '$Machine'"); $StatementHandle->execute(); while(my $RecordData = $StatementHandle->fetchrow_hashref) { $Service_Info{ $RecordData->{Service} } = $RecordData->{Server +Name}; } my $WMIServices = Win32::OLE->GetObject("winmgmts:\\\\$Machine\\ro +ot\\CIMV2"); my $Services = $WMIServices->ExecQuery("SELECT * FROM $Class"); foreach my $Service ( in($Services)) { if(defined $Service_Info{ $Service->{DisplayName} }) { $StatementHandle = $DataHandle->prepare("UPDATE dbo.Servic +es SET ServerName = '$Machine', IP_Address = '$IP', Username = '$Service->{StartName}', Service = '$Service->{DisplayName}' where ServerName = '$Machine' AND Service = '$S +ervice->{DisplayName}'"); $StatementHandle->execute(); undef $Service_Info{ $Service->{DisplayName} }; } else { if ($Service->{DisplayName} ne "") { if ($Service->{StartName} ne "") { $Service->{DisplayName} =~ s/'/ /g; $StatementHandle = $DataHandle->prepare("INSERT IN +TO dbo.Services (ServerName, IP_Address, Username, Service) VALUES ('$Machine', '$IP', '$Service->{StartNa +me}', '$Service->{DisplayName}')"); $StatementHandle->execute(); undef $Service_Info{ $Service->{DisplayName} }; } } } } } 1;

In reply to Problems with uninitialized value by SteveS832001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.