GertMT has asked for the wisdom of the Perl Monks concerning the following question:
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 (<INPUT>) { 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 (<INPUT>) { { for ( $i = 0 ; $i < scalar @order ; $i++ ) { if (m/^$order[$i]/) { print MYFILE } } } } close(INPUT); close(MYFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Split up file depending unique values 1st column
by jwkrahn (Abbot) on Dec 16, 2006 at 23:36 UTC | |
by GertMT (Hermit) on Dec 17, 2006 at 12:54 UTC | |
by jwkrahn (Abbot) on Dec 17, 2006 at 16:12 UTC | |
by GertMT (Hermit) on Dec 17, 2006 at 19:20 UTC | |
|
Re: Split up file depending unique values 1st column
by graff (Chancellor) on Dec 16, 2006 at 23:20 UTC | |
by GertMT (Hermit) on Dec 17, 2006 at 13:07 UTC |