#!/usr/bin/perl -w use strict; my $file = ''; $file = shift @ARGV unless $file; unless ($file) { print "Please input a filename: "; chomp ($file = <>); } my %change = ( HEAL => 'NOTE Medical:', HIST => 'NOTE Biography:', EDUC => 'NOTE Educated:', RESI => 'NOTE Resided:', OCCU => 'NOTE Occupation:'); open (FILE, "<$file") or die "Unable to open $file: $!"; my @data = ; close FILE; my $change_this = join "|", keys %change; $change_this = qr/($change_this)/; my $found_sour = 0; my $last_line = ''; for (@data) { # make the IBM DOS to ASCII substitution s/1 CHAR IBM DOS/O CHAR ASCII/; s/$change_this/$change{$1}/g; $found_sour = 0 if m/^0/; $found_sour = 1 if m/^0.+SOUR\s*$/; if ($found_sour == 1) { $found_sour++ if s/1 NAME/1 TITL/; } elsif ($found_sour) { s/1 NAME/2 CONT/; } # fix the name problem if ($last_line =~ m/\bINDI\s*$/) { if (m/1\s*NAME/) { s|([\w.]+)|($1 eq "NAME")? $1 :ucfirst lc $1|eg; # the MacDonald fix, the \b (boundary) condition # and the quote check should limit appropriately # Names like Mace and Mack are treated as special # cases as this is the only way to deal with them s # substitute regex / # opening delimiter for regex (?; unless ($input =~ m/y/i) { print "Aborting!\n"; exit; } } open (FILE, ">$file") or die "Unable to create $file: $!"; print FILE @data; close FILE; print "Data written to $file OK!";