use strict;
use diagnostics;
use warnings;
use vars qw! $file $col @F $val $count @order %count $i !;
my $file = $ARGV[0];
open( INPUT, $file ) || die "does not work: $!";
$col = 0;
while () {
s/\r?\n//;
@F = split /,/, $_;
$val = $F[$col];
if ( !exists $count{$val} ) { push @order, $val }
$count{$val}++;
}
foreach $val (@order) { print "$val\n" }
close(INPUT);
open( INPUT, $file ) || die "does not work: $!";
open( MYFILE, ">printhere.txt" ) or die "does not work $!";
while () {
{
for ( $i = 0 ; $i < scalar @order ; $i++ ) {
if (m/^$order[$i]/) { print MYFILE }
}
}
}
close(INPUT);
close(MYFILE);