#!/usr/local/bin/perl # replace any occurence of # # ##KEY # # by its value in the dictionnary file. The dictionnary file contains lines of # the form # # ##KEY VALUE # # where KEY is the first word on the line and VALUE est the rest of the line $ARGV[0] || die("usage: $0 dictionnary\n"); open KEYS, $ARGV[0] || die("\n\n!!! could not open dictionnary file $ARGV[0] !!!\n\n"); # load dictionnary file while () { chop; ($key, $value) = /^\s*(##\w+)\s*(.*)$/; $kv{$key} = $value; } # substitute while () { chop; ($key) = /\.*(##\w+)\.*/; if ($key) { $kv{$key} || die("\n\n!!! no value found for key >$key< !!!\n\n"); s/$key/$kv{$key}/g; } print "$_\n"; }