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

In reply to removing a column by jn64024

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.