Apart from that, I have to ask: where does your input file come from? How confident are you that it would never contain something that you wouldn't want included in a shell command line?s/\s+$//; # instead of chomp
If you were to add "-T" on the shebang line of your script, it would die rather than do `host $host`, and with good reason.
Now, if you were to use a module, like Net::DNS::Nslookup (and there may well be others), you could get the IP addresses you want without having to run a shell command in back-ticks for each one. And you wouldn't need to worry about pesky little details like an input file that might contain shell-magic characters in the first column. Instead, your script could look like this:
Maybe that doesn't do exactly what you intended, and maybe you'd rather just use the command-line "host" utility - in that case, do be careful about your input...use strict; use Net::DNS::Nslookup; # ... do whatever you do open FH and load MYDB # (I'll fake it for now...) my %MYDB = ( 'WWW.PERLMONKS.ORG' => 'TPF' ); while (<DATA>) { s/\s+$//; my @hostpair = split ' '; my $HOST = uc( $hostpair[0] ); my $nslookup = Net::DNS::Nslookup->get_ips( $hostpair[0] ); for my $addr ( split( /\n/, $nslookup )) { my ( $name, $ip ) = split( /,/, $addr ); my $OWNER = ( exists( $MYDB{$HOST} )) ? $MYDB{$HOST} : "OTHER" +; print "$hostpair[0]\t$ip\t$OWNER\n"; } } __DATA__ www.perlmonks.org google.com
In reply to Re: Leading Characters Not Visible for Certain Array Elements While Printing
by graff
in thread Leading Characters Not Visible for Certain Array Elements While Printing
by justsomeguy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |