vlad3848 has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl prints only one line when directed to a file but print to a screen works
by Happy-the-monk (Canon) on Jun 30, 2013 at 17:17 UTC | |
by vlad3848 (Acolyte) on Jun 30, 2013 at 17:52 UTC | |
|
Re: Perl prints only one line when directed to a file but print to a screen works
by hdb (Monsignor) on Jun 30, 2013 at 17:17 UTC | |
by vlad3848 (Acolyte) on Jun 30, 2013 at 17:51 UTC |