in reply to Re^3: Perl $ENV hash
in thread Perl $ENV hash

what is wrong here. nothing is printing to the file, list.txt
#use warnings; #use DBI; use Win32; use Win32::OLE qw (in); open(HLOG,">c:/temp/logf.txt") || die " Open Log_file: $!"; open(HLIST,">C:/temp/list.txt") || die " Open list.txt: $!"; #my $dbh = DBI->connect('dbi:DBI:'); while(<>) { chomp($_); @a = `ping -n 1 $_`; print "for $_:"; if ("@a" =~ /Request timed out/i || "@a" =~ /could not find host/i + ){ print "<<<<not Alive>>>>>\n"; #TODO #spit it to non-alive txt file #close file print(HLOG); } else { print "::: Alive\n"; my $Class = "WinMgmts://$_"; my $Wmi = Win32::OLE->GetObject ($Class); if ($Wmi) { my %Vars = $Wmi->ExecQuery("SELECT * FROM $Win32_Environme +nt"); print $Vars; foreach (keys %Vars) { print HLIST $Vars{$_} ."\n"; } } else { print "NO idea"; } #TODO: if alive, check if cadmap exists, if yes, spit the var= +value pair to a log.txt file. } } close (HLOG) || die "Close: $!"; close (HLIST) || die "Close:$!";

Replies are listed 'Best First'.
Re^5: Perl $ENV hash
by Corion (Patriarch) on Apr 20, 2010 at 19:22 UTC

    You are not using the strict pragma. If you had done so, Perl would have forced you to declare all variables you use. That would have shown you that there is no variable declared with the name $Win32_Environment, but you try to use it in your string.

      that was a mistake. I removed the '$'. But still didnt work I tried something else
      if ($Wmi) { my $Vars = $Wmi->Get('Win32_Environment'); my $var = $Vars->Spawninstance_ (); #print $var; print $var ->{'CADMAP'}; $var->put_(); #print HLIST $Vars{"pc_os"}; #foreach (keys %Vars) { # print HLIST $Vars{$_} ."\n"; #} }
      Still no luck.