I'm new to using perl. Basically what I'm trying to do is slice up a csv file and perform two actions with it, one iterate through certain columns and confirm DNS entries exist for certain systems and they are accurate and output anything that doesn't match and secondly generate nagios configuration files for any entry which has an IP address. I'm stuck at this point, my code states "Use of uninitialized value $hostip in string at C:/Users/akuncewitch/workspace/Sec Ops Engineering Toolkit/nagiosgen.pl line 15, <F> line 1." When I run it but I have no idea what I'm missing. I've written several fairly simple Perl scripts that sliced up csv and even performed actions in a loop, so I'm not sure what I'm missing this time.

perl 5, version 12, subversion 4 (v5.12.4) built for MSWin32-x64-multi-thread Binary build 1205 294981 provided by ActiveState http://www.ActiveState.com Built Jun 20 2011 18:11:54

use warnings; #Read Security Engineering Inventory CSV Export and puke @ failure my $file = 'C:/perl64/seceng.csv'; my $hostpath = 'C:/perl64/nagios/hosts/'; #my $hostpath = '/usr/local/nagios/etc/objects/hosts/'; open (F, $file) || die ("Could not open $file!"); while (<F>) { @fields = split(',', $_); $hostname = $fields[3]; $hostip = $fields[5]; if(-e "$hostip"){ open (HOST, 'C:/perl64/nagios/hosts/' . $hostname) || die "Couldn' +t open: $!"; printf HOST "define host\{"; printf HOST "use linux-server;\n"; printf HOST "host_name $host;\n"; printf HOST "alias $host;\n"; printf HOST "address $hostip;\n"; printf HOST "\}"; } } close F;

In reply to Question on loops and variables by bogonspace

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.