foreach and variables problem

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?


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("");
$hostname = ($result->{""});

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

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

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




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.

Howdy, Stranger!

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