#!/usr/bin/perl -w use strict; use Text::Template; my %vars; my $line; my @fields; my $result; my $file = "/home/trixee/20010814/remap.tmpl"; my $cfg = "/home/trixee/20010814/remap.config"; my $template = new Text::Template (SOURCE => $file) or die "Couldn't construct template: $Text::Template::ERROR"; open FH, "$cfg" or die "$!\n"; while ($line = ) { chomp $line; next if ($line =~ /^\#/); @fields = qw(map proto uri1 uri2); if ( @vars{@fields} = $line=~m!(map|reverse_map)\s+(\w+)://(.*?)\s+\2://(.*?)$! ) { $result = $template->fill_in(HASH => \%vars); } if ($result) { print "$result\n"; } else { die "Couldn't fill in template: $Text::Template::ERROR" } } __DATA__ # Automatic mapping tables generated from Magma map http://www.digitalcity.com http://origin-www.digitalcity.com map tunnel://www.digitalcity.com tunnel://origin-www.digitalcity.com map http://10.0.2.1 http://origin-www.digitalcity.com map tunnel://10.0.2.1 tunnel://origin-www.digitalcity.com reverse_map http://origin-www.digitalcity.com http://www.digitalcity.com reverse_map tunnel://origin-www.digitalcity.com tunnel://www.digitalcity.com Template: {$map} {$proto}://{$uri1} {$proto}://{$uri2} {$map} {$proto}://{$uri1} {$proto}://{$uri2} {$map} {$proto}://{$uri1} {$proto}://{$uri2} {$map} {$proto}://{$uri1} {$proto}://{$uri2} {$map} {$proto}://{$uri2} {$proto}://{$uri1} {$map} {$proto}://{$uri2} {$proto}://{$uri1}