jn64024 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: removing a column
by toolic (Bishop) on Jun 17, 2009 at 20:50 UTC | |
|
Re: removing a column
by johngg (Canon) on Jun 17, 2009 at 22:47 UTC | |
by poolpi (Hermit) on Jun 18, 2009 at 09:07 UTC | |
by jn64024 (Initiate) on Jun 18, 2009 at 14:26 UTC | |
|
Re: removing a column
by VinsWorldcom (Prior) on Jun 17, 2009 at 20:53 UTC | |
|
Re: removing a column
by jwkrahn (Abbot) on Jun 17, 2009 at 22:11 UTC |