Overall I am attempting to run a socket cmd on a list of IP's. I am capturing this list of ip's from an /etc/hosts file. This file is structured as two columns. Ip's on the left and device names on the right seperated by a tab.
The following code skips commented lines, pulls out any spaces between lines and pushes it into an array for eventual sorting, removal of duplicates and then running the socket cmd against the final list. I however cannot figure out how to remove the second column from the array.
My print cmds are for testing only to view my output. Here is what I have so far. Anythoughts on how I can remove the second column from the array?
#!/usr/bin/perl
use strict;
use Socket;
my ( @hostcontents
,@uniquearray
,@ipaddresses
,@linesplit
,@line
) = ();
my $line = ();
my $hostfile = "/tmp/jn/hosts";
my %seen=();
my $logfile = "/tmp/jn/logforthisserver.log";
open(HOSTFILE,"<$hostfile");
foreach (<HOSTFILE>){
if($_ =~ m/^#/){next;}
if($_ =~ m/^\s$/){next;}
push (@hostcontents,$_);
}
close(HOSTFILE);
print "Current hostcontents:\n@hostcontents\n";
foreach my $temp (@hostcontents){
#print "my line is: $line";
#@linesplit = split($split,$line);
#@linesplit = split(/\t+/,$line);
#@linesplit = split(" ",$line);
#@linesplit = split(/\s+/, $_)[0];
#print "Test:$line";
}
#print "Current linesplit:\n@linesplit\n";
#foreach $line (@linesplit) {
# next if $seen{$line}++;
# push(@uniquearray,$line);
# $seen{$line}++;
# print"Seen Hash is:\n @{[ %seen ]}\n";
#}
#Sort the array
@uniquearray=sort(@uniquearray);
#foreach my $line (@uniquearray){
# print "$line";
#SOCKET JUNK
#}
# open (LOGFILE,">$logfile");
# print LOGFILE (@ipaddresses);
# close(LOGFILE);
#}#end foreach