Skip to content

Instantly share code, notes, and snippets.

@autarch
Created November 8, 2015 19:55
Show Gist options
  • Select an option

  • Save autarch/da744699061efabb0dcc to your computer and use it in GitHub Desktop.

Select an option

Save autarch/da744699061efabb0dcc to your computer and use it in GitHub Desktop.
use v6;
use Text::CSV;
sub MAIN ( IO() :$in, IO() :$out ) {
my $csv_in = Text::CSV.new;
my $csv_out = Text::CSV.new( :eol("\r\n") );
my $in_fh = $in.open(:r);
my $out_fh = $out.open(:w);
$csv_out.print( $out_fh, < person_id event > );
my $position;
while my @fields = $csv_in.getline($in_fh) {
next unless @fields.any;
if @fields[0] ~~ m/^ <[ A .. Z \c[SPACE] ]>+ $/ {
$position = @fields[0].split(q{ }).map({ m/^ CAA || PPV $/ ?? .uc !! .tclc }).join(q{ });
next;
}
next unless @fields[*-1] ~~ m/<[ y x ]>/;
die 'No position defined yet'
unless defined $position;
my $event = 'Twin Cities Veg Fest 2015 ';
$event ~= $position;
$event ~= q{ } ~ @fields[0] if @fields[0];
$csv_out.print( $out_fh, @fields[*-2], $event );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment