#!/usr/bin/perl -w use strict; my @Fields; my @Array; open (FILE,"file") or die "Can't open file\n"; while (<FILE>) { next if (/^#/); @fields = split "\t" , $_; next unless (@Fields == 7); push @Array , [ @Fields[0,3,6] ]; } foreach my $foo (@fields) { print "$foo->[2]\n" if ($foo->[2] != 3); }
You are confused as to why the code won't work (scratching head) - oh, I see my mistake - there is a trailing newline at the end - let me just get rid of it.
push @Array , [ @Fields[0,3,6] ]; } chomp @Array; foreach my $foo (@fields) { print "$foo->[2]\n" if ($foo->[2] != 3); }
Now it still doesn't work - this time you are getting some error about not being able to use a stringified array as a reference with strict enforced.
you remove the chomp as is and you put it back in the code that builds the array
while (<FILE>) { next if (/^#/); @fields = split "\t" , $_; next unless (@Fields == 7); chomp $Fields[6]; push @Array , [ @Fields[0,3,6] ]; }
You are happy your code is now working, but you are sad that you have to do it THAT way.
so friendly monks - is there a way to chomp an AoA similar to:
chomp @Array;
Thanks in advance - L~R
In reply to Chomp an AoA? by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |