#!/usr/local/bin/perl

##########################
# Program description:
# This program reads a file with Språkbanken resource abbrevations and 
#  names (nameReplacements.txt), then calls a shell script that creates
#  a new file from a template and replaces relevant names as needed.
#
# Author: Martha Dís Brandt (martha.brandt@svenska.gu.se)
#  for Språkbanken (http://spraakbanken.gu.se)
# Date: April 11th 2011
##########################


my $input = shift(@ARGV);

open(INPUT, "$input") or die "Could not open file: $!";


## Read input
my ($line, @tokens, $abbrev, $name, %myHash);
while ($line = <INPUT>) {
  chomp($line);
  @tokens = split / /, $line;
  $abbrev = $tokens[0];
  $name = $tokens[1];
  $myHash{$abbrev} = $name;
}


## For each pair in the hash, execute the shell script
while (($abbrev, $name) = each(%myHash)){
#  print "$abbrev, $name, EOL.\n";
  system("sh resource_to_olac-cmdi.sh $abbrev $name");
}


close(INPUT) or die "Could not close file: $!";
