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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.