Created
September 10, 2009 19:42
-
-
Save fletch/184768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/perl | |
## | |
## Slightly more idiomatic and optimized Perl of 2num.pl from | |
## http://github.com/brendano/awkspeed/tree/master | |
## | |
use strict; | |
use warnings; | |
open( my $vocab_fh, '>', "vocab" ) or die "vocab: $!\n"; | |
my %jmap; | |
my %i_file; | |
my $j_ctr = 0; | |
for my $infile ( @ARGV ) { | |
print STDERR "new file $infile\n"; | |
open( my $in_fh, '<', $infile ) or die "$infile: $!\n"; | |
open( my $out_fh, '>', "${infile}n" ) or die "${infile}n: $!\n"; | |
my %imap; | |
my( $ival, $jval ); | |
while( <$in_fh> ) { | |
my( $item, $feat, $val ) = split( / / ); | |
$ival = ($imap{$item} ||= ++$i_file{ $infile }); | |
print $vocab_fh qq{$feat\n} unless exists $jmap{ $feat }; | |
$jval = ($jmap{$feat} ||= ++$j_ctr); | |
print $out_fh qq{$ival $jval $val}; | |
} | |
} | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment