title: Try to remove specific columns using splice in Perl
body: <p>I am a brand new Perl novice, looking for help with my first ever Perl script</p>
  
  <p>I have some huge files 30-50GB files and they are constructed like this - millions of columns and thousands of rows:</p>
  
  <pre><code>A B C D E 1 2 3 4 5 6 7 8 9 10 
  A B C D E 1 2 3 4 5 6 7 8 9 10 
  A B C D E 1 2 3 4 5 6 7 8 9 10 
  A B C D E 1 2 3 4 5 6 7 8 9 10 
  A B C D E 1 2 3 4 5 6 7 8 9 10 
  A B C D E 1 2 3 4 5 6 7 8 9 10 
  A B C D E 1 2 3 4 5 6 7 8 9 10
  </code></pre>
  
  <p>I would like to delete column "A", and column "C", then ever third of the number columns, so the "3" column and the "6" column, then "9" column until the end of the file. Space delimited.</p>
  
  <p>My attempt is like this:</p>
  
  <pre><code>#!/usr/local/bin/perl
  
  use strict;
  use warnings;
  
      my @dataColumns;
      my $dataColumnCount;
      if(scalar(@ARGV) != 2){
          print "\nNo files supplied, please supply file name\n";
          exit;
      }
  
      my $Infile = $ARGV[0];
      my $Outfile = $ARGV[1];
  
      open(INFO,$Infile) || die "Could not open $Infile for reading";
      open(OUT,"&gt;$Outfile") || die "Could not open $Outfile for writing";
  
      while (&lt;INFO&gt;) {
          chop;
          @dataColumns = split(" ");
          $dataColumnCount = @dataColumns + 1;
  #Now remove the first element of the list
          shift(@dataColumns);
  
  #Now remove the third element (Note that it is now the second - after removal of the first)
          splice(@dataColumns,1,1); # remove the third element (now the second)
  
  #Now remove the 6th (originally the 8th) and every third one thereafter
  #NB There are now $dataColumnCount-1 columns
  
          for (my $i = 5; $i &lt; $dataColumnCount-1; $i = $i + 3 ) {
              splice($dataColumns; $i; 1);
          }
  
  #Now join the remaining elements of the list back into a single string
          my $AmendedLine = join(" ",@dataColumns);
  
  #Finally print out the line into your new file
          print OUT "$AmendedLine/n";
  }
  </code></pre>
  
  <p>But I am getting a few weird errors:</p>
  
  <ol>
  <li>It is saying it doesn't like my $1 in the for loop, I have added a 'my' which seems to make the error go away but nobody else's for code seems to contain a 'my' here so I am not sure what is going on.</li>
  </ol>
  
  <p>Global symbol "$i" requires explicit package name at Convertversion2.pl line 36.
  Global symbol "$i" requires explicit package name at Convertversion2.pl line 36.
  Global symbol "$i" requires explicit package name at Convertversion2.pl line 36.
  Global symbol "$i" requires explicit package name at Convertversion2.pl line 36.</p>
  
  <ol>
  <li>The other error is this:
  syntax error at Convertversion2.pl line 37, near "@dataColumns;"
  syntax error at Convertversion2.pl line 37, near "1)"</li>
  </ol>
  
  <p>I am not sure how to correct this error, I think I am almost there, but not sure what exactly what the syntax error is, is am unsure how to fix it.</p>
  
  <p>Thank you in advance.</p>