in reply to HELP - nslookup in perl
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: HELP - nslookup in perl
by setantae (Scribe) on Mar 25, 2000 at 02:42 UTC | |
|
RE: Re: HELP - nslookup in perl
by btrott (Parson) on Mar 23, 2000 at 22:03 UTC |