Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cgutteridge/Grinder
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutteridge committed Aug 23, 2011
2 parents cbdec75 + 8895759 commit 7555654
Show file tree
Hide file tree
Showing 13 changed files with 810 additions and 102 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Grinder:
Grinder:

etc/ bin/grinder.pl and lib/ are LGPL.
perl-lib/ is the liceses of the packages we've added.
Expand Down
55 changes: 55 additions & 0 deletions bin/apply-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/perl

use strict;
use warnings;

use Text::CSV;

my $csv = Text::CSV->new();
binmode(STDIN, ":utf8" );
binmode(STDOUT, ":utf8" );

my $skip_rows = 1;
my $map_file = $ARGV[0];
my $field_number = $ARGV[1]-1;

my $map = {};
open( MAP, "<:utf8", $map_file ) or die "can't read $map_file: $!";
while( my $line = readline( MAP ) )
{
if( !$csv->parse($line) )
{
my $err = $csv->error_input;
die( "Failed to parse line: $err", 1 );
}
my @row = $csv->fields();
$map->{$row[1]} = $row[0];
}
close MAP;


my $line_n = 0;
while( my $line = readline( STDIN ) )
{
$line_n++;
if( !$csv->parse($line) )
{
my $err = $csv->error_input;
die( "Failed to parse line: $err", 1 );
}
if( $skip_rows ) { $skip_rows--; next; }
my @row = $csv->fields();
if( defined $row[$field_number] && $row[$field_number] ne '' )
{
my $mapped = $map->{$row[$field_number]};
if( !defined $mapped)
{
die "Unmapped value on line $line_n: \"".$row[$field_number]."\"";
}
$row[$field_number] = $mapped;
}

$csv->print (*STDOUT, \@row );
print "\n";
}

6 changes: 0 additions & 6 deletions bin/dev8d.sh

This file was deleted.

Loading

0 comments on commit 7555654

Please sign in to comment.