develooper Front page | perl.beginners | Postings from September 2008

looping through multiple arrays

Thread Next
From:
Bobby
Date:
September 4, 2008 08:22
Subject:
looping through multiple arrays
Hi,

I have a large pipe delimited text file that i want to loop through and sort out a column of data within that file. Let's call this column $sizes. I want to group these different sizes into categories. i.e.
@sizeA = ("A","B","C");
@sizeB = ("D","E","F");
@sizeC = ("G","H","I");

This is what i want to do:

If $sizes is in @sizeA
print the sizes that are listed in @sizeA

If $sizes is in @sizeB
print the sizes that are listed in @sizeB

same for @sizeC. 

Could someone show me how to do this? Below is what i have so far. Thanks.

#!/usr/bin/perl
use strict;
use warnings;

open(IN, $ARGV[0]) || die "Could not open data file: $ARGV[0]\n";
my @sizes = (<IN>);

foreach my $line (@sizes)
{
        # split rows into columns
        my @fields = split "\t", $line;
        my $size = $fields[2];
}
close(IN);





      

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About