There are some Perl-ings you need to understand first:
my $infile = $ARGV[0];
This line reads the first command line argument after your script name and pass to the variable $infile
open (my $infile, "<", "namconvmars.txt")
or die "Can't read from $infile: $!";
You are declaring again $infile (that is what my does), also you are reusing the variable to be a file pointer. So, you don't need the first line my $infile = $ARGV[0] because you never used it.
my (@group1, @group2, @group3);
while (<$infile>){
my @cols = split(/\t/);
push @group1, @cols[0];
push @group2, @cols[1];
push @group3, @cols[2];
print "@group1\t@group2\t@group3";
}
close $infile
On this part I think you want to collect the values, but if your intention is to simply convert each line, you don't need the arrays, just read, modify and print each line. The complex part I see, when you split the line using spaces, the second element is splitted too ("Ana Biba" -> ["Ana", "Biba"], to avoid this you will need to reconstruct that element. Something like:
#!/usr/bin/perl
use strict;
use warnings;
my $file = "namconvmars.txt";
open (my $infile, "<", $file)
or die "Can't read from $file";
while (<$infile>){
my @cols = split(/\s+/, $_); # break line using spaces
my $first = shift(@cols); # grab first element
my $last = pop(@cols); # grab last element
my $mid = join " ", @cols; # reconstruct middle element
print join "\t", $first, $mid, $last;
}
close $infile
how is it related to bioinformatics ?