Raja Vadlamudi wrote:
On Thu, Sep 4, 2008 at 12:36 PM, Raja Vadlamudi <[EMAIL PROTECTED]> wrote:
On Thu, Sep 4, 2008 at 11:22 AM, Bobby <[EMAIL PROTECTED]> wrote:
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);
One mistake would be using '||' instead of 'or' in open. Use this instead.
open(IN, $ARGV[0]) or die "Could not open data file: $ARGV[0]\n";
With the parentheses around open's arguments it doesn't matter if you
use '||' or 'or'. Without the parentheses only 'or' will work correctly.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/