I am trying to print a list of the devices that match my specific criteria. When I print everything to the screen, it works great. However, when I print it to a file it only prints one line. I am new to perl so any help would be appreciated. Thanks
open OVERWRITE, ">overwrite.txt" or die $! $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 > primaryIPAddr +ess; $deviceHash{"hostName"} = $listDevices->hostName; # mapping array my @returnData = ( "deviceID", "hostName", "primaryIPAddress", "deviceType", "vendor", "model" ); # 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} . " +,"; } } } &closeConnection($dbConnection); } close OVERWRITE;
In reply to Perl prints only one line when directed to a file but print to a screen works by vlad3848
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |