title: How to search and replace a column in a CSV via perl?
body: <p>So, I'm super new to perl... I'm on a windows box within a Corporate network. I am unable to download CPAN modules... </p>
  
  <p>I have a CSV that is exported with multiple columns, the 2nd column contains 2 rows with text and the rest of the rows are IP addresses. I need to change the first 3 octets of the IP for all the rows excluding the text obviously. I then need to either save it to the same file, or create a new one... I also need all the other columns to remain in the document. I've looked and looked and everyone suggests modules which makes sense but I cannot get them. Here is my code:</p>
  
  <pre><code>if ( $cmd[0] eq "update" ) {
      print "Old subnet ex: 10.0.0\n";
      my $oldsubnet = &lt;STDIN&gt;;
      chomp $oldsubnet;
      print "New subnet ex: 10.0.0\n";
      my $newsubnet = &lt;STDIN&gt;;
      chomp $newsubnet;
  
      my $file = "path\\file.csv";
  
      open( my $fh, '&lt;', $file ) or die "'$file' would not open $!";
  
      while ( my $line = &lt;$fh&gt; ) {
          chomp $line;
          my @fields = split ",", $line;
          my $string = $fields[1];
  
          $string =~ s/$oldsubnet/$newsubnet/g;
  
          my $ofile = "path\\test.csv";
  
          open( my $ofh, '&gt;&gt;', $ofile ) or die "'$ofile' would not open $!";
          print $ofh "$string\n";
      }
  }
  </code></pre>
  
  <p>So I just end up with a single column with the updated IP's with this code. How in the world do I get the rest of the CSV... Is there an easier way to just replace the IP's???? It seems like this would be easy but the CSV is making it hard. Any help would be appreciated. P.S. I am using strict and warnings :)</p>
  
  <p>So just to clarify I am aware that @fields is being left out and thus not being printed... What I'm asking is how do I update only the data in the 2nd column and then put the whole document back into a new file?</p>