foreach and variables problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

foreach and variables problem

sconossconos Posts: 1Member
Kind of new to Perl, having a problem with a foreach loop reading a log file - each line in the logfile has a format of datastring=datanumber and I'm splitting on the "=" - the curious thing that I'm having a problem with no matter how many lines in the log file - I only get variable return from each datastring in the log file and just the last datanumber in the log file?

/----------------------------------

#!c:Perlinperl.exe
use Net::SNMP;
use CGI qw(:standard);

$LOGFILE = "stormon.log";
open(LOGFILE) or die("Could not open log file.");
foreach $line () {

($hostip, $driveid,) = split('=',$line);

($session,$error) = Net::SNMP->session(Hostname => $hostip,
Community => "public");
die "session error: $error" unless ($session);

# This gets hostname from System OID
$result = $session->get_request("1.3.6.1.2.1.1.5.0");
$hostname = ($result->{"1.3.6.1.2.1.1.5.0"});

# This gets Drive Letter & Label from Host OID
$result = $session->get_request("1.3.6.1.2.1.25.2.3.1.3." . $driveid . "");
$drivename = ($result->{"1.3.6.1.2.1.25.2.3.1.3." . $driveid . ""});

die "request error: ".$session->error unless (defined $result);

print ( $hostname," , ", $drivename,"
" ) ;

$session->close;

}
close(LOGFILE);

/-------------------------------------------------------------

For a return I get

hostname1 ,
hostname2 , drivelabel

Played with the variables and this should work, but I can't see were its breaking.

TIA Mike
Sign In or Register to comment.