特定の条件に一致するデバイスのリストを印刷しようとしています。すべてを画面に印刷すると、うまく機能します。ただし、ファイルに出力すると、1行しか出力されません。私はperlが初めてなので、助けていただければ幸いです。ありがとう
$dbConnection = &openConnection();
# run the "list_device" command via the initial connection
my $device_list = $dbConnection->list_device();
foreach my $listDevices ($device_list->result()) {
if ( ($listDevices->model !~ /PIX/)
&& ($listDevices->model !~ /ASA/)
&& ($listDevices->model !~ /ACE/)
&& ($listDevices->driverName !~ /Context/)
&& ($listDevices->hostName =~ /^ls1.*/i)
&& ($listDevices->vendor =~ /Cisco/)
) {
#create device hash for LS
$deviceHash{"deviceID"} = $listDevices->deviceID;
$deviceHash{"deviceType"} = $listDevices->deviceType;
$deviceHash{"vendor"} = $listDevices->vendor;
$deviceHash{"model"} = $listDevices->model;
$deviceHash{"primaryIPAddress"} = $listDevices > primaryIPAddress;
$deviceHash{"hostName"} = $listDevices->hostName;
# mapping array
my @returnData = (
"deviceID", "hostName",
"primaryIPAddress", "deviceType",
"vendor", "model"
);
open OVERWRITE, ">overwrite.txt" or die $!
# loop through the hash and print out the device information
foreach my $data (@returnData) {
my $returnDataLength = @returnData;
if (exists $deviceHash{$data}) {
print OVERWRITE $deviceHash{$data} . ",";
}
}
close OVERWRITE;
}
&closeConnection($dbConnection);
}