If this the actual code you tried to run? This doesn't even compile, much less "work". Here's what you need to fix. You have:
#!/usr/bin/perl
As chromatic said, change this to
#!/usr/bin/perl -w use strict;
"-w" enables warnings, and "use strict" forces you to declare your variables, prevents you from using barewords that aren't subroutines, and prevents you from using symbolic references. Good for any level of programmer.

So, with strict enabled, you should declare your $INPUT_FILE variable as a lexical variable, using my:

my $INPUT_FILE = "ipnum";
What's next, then? You've got this:
open(INPUT_FILE); @array = ; close(INPUT_FILE);
There are several things wrong here. First, that's now how open works. It takes *two* arguments: a filehandle and the filename (read perldoc -f open for more details). Also, as chromatic suggested, check the status of your open and close calls! Always check the return value of a system call!

Second, that next line doesn't even compile. You want to read from the filehandle--Perl makes that quite simple.

So we'll replace what you have with this:

open INPUT_FILE, $INPUT_FILE or die "Can't open $INPUT_FILE: $!"; my @array = <INPUT_FILE>; close INPUT_FILE or die "Can't close $INPUT_FILE: $!";
Finally, you've got the loop that calls nslookup for each IP address in the file. One real problem here--as previously mentioned, you used single-quotes instead of backticks. You need backticks (`) in order to actually make the system call. Otherwise it's just a single-quoted string, which is nothing special.

Second, you're looping over "@arrays"--but you never defined "@arrays". You defined "@array". Perhaps this was a typo?

So, with that in mind (and with the name of your loop variable changed to reflect more accurately the value it contains):

for my $address (@array) { my $output = `nslookup $address`; print $output; }
So that's it. I realize that the end result of the code doesn't differ much from what other posters have written, but I hope that the explanation I've provided might help in the future, or the present.

In reply to Re: HELP - nslookup in perl by btrott
in thread HELP - nslookup in perl by Anonymous Monk

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.