Reorder list.pl
Jump to navigation
Jump to search
#!/usr/bin/perl #reorders the list use warnings; use strict; sub feature_sort; # read in file # if it pattern matches open( THE_CPP, "FeatureNames.cpp" ) or die "wtf?\n"; my %line_hash; while( <THE_CPP> ) { if( $_ =~ /^\told_features_.*= "(.*)";/ ) { push @{ $line_hash{ $1 } }, $_; } } close THE_CPP; open ( OUT, '>', "sorted_old_feat_names.txt") or die "aye carumba!\n"; my $line_count = 0; foreach my $featurename ( sort feature_sort keys %line_hash ) { foreach my $old_featurename ( sort @{ $line_hash{ $featurename } } ) { ++$line_count; #print $line_count . ".) " . $old_featurename; print OUT $old_featurename; } } close OUT; sub feature_sort { my ($a_stem, $a_bin, $b_stem, $b_bin ); if( $a =~ /(.*) \[(\d+)\]/ ) { $a_stem = $1; $a_bin = $2; } if( $b =~ /(.*) \[(\d+)\]/ ) { $b_stem = $1; $b_bin = $2; } if ( $a_stem && $a_bin && $b_stem && $b_bin ) { if ($a_stem ne $b_stem ) { return $a cmp $b } else { return $a_bin <=> $b_bin; } } else { return $a cmp $b; } }