This does a few things your code doesn't. First, it enables warnings (-w) and uses the strict pragma. These will help you detect errors and help you become a better Perl programmer. Next, it creates a local filehandle, named INPUT, within a block -- just a good idea if you this will ever be part of another program. It also dies, displaying error messages, if the open or close calls fail -- very important. Always check these calls. $! is your friend here. The rest of it should be pretty self-evident. (Especially after the ever-vigilant btrott pointed out a couple of errors and I corrected another.)#!/usr/bin/perl -w use strict; my $input_file = "ipnum"; my @array; { local *INPUT; open(*INPUT, $input_file) or die "Cannot open: $!"; @array = <INPUT>; close(*INPUT) or die "Cannot close: $!"; } foreach my $address (@array) { my $output = `nslookup $address`; print $output, "\n"; }
In reply to Re: HELP - nslookup in perl
by chromatic
in thread HELP - nslookup in perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |