oblate kramrdc has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to convert a series of strings
MOVE 4 TO INT1.
DISPLAY 'MEMBERS OF THE GROUP'.
DISPLAY INT1.
to
INT1 := 4;
PUT("MEMBERS OF THE GROUP : ");
PUT(INT1);
I used this codes:
use strict; use warnings; my $SOURCEFILE; my $TARGETFILE; my $REPORTFILE; my $converted; my $discarded; my $holder; print "Enter filename to convert: "; chomp($SOURCEFILE = <STDIN>); print "Save to:"; chomp($TARGETFILE =<STDIN>); print "Save Conversion Report to:"; chomp($REPORTFILE =<STDIN>); open SOURCEFILE, '<', $SOURCEFILE or die "Can't open $SOURCEFILE: $!"; open TARGETFILE, '>', $TARGETFILE or die "Can't open $TARGETFILE: $!"; open REPORTFILE, '>', $REPORTFILE or die "Can't open $REPORTFILE: $!"; $converted=0; $discarded=0; sub reporting { print TARGETFILE $holder; print REPORTFILE " -> "; print REPORTFILE $holder; $converted++; } foreach my $line (<SOURCEFILE>) { if($line =~ /\bDISPLAY\s'([^']*)'\./) { $line = "PUT(\"$1\");\n"; $holder = $line; reporting; } elsif ($line =~ /\bMOVE/) { print REPORTFILE $line; $line =~ m/MOVE (\d+) TO ([\d\w]+)/; print TARGETFILE "$2 := $1;\n"; print REPORTFILE " -> "; print REPORTFILE "$2 := $1;\n"; $converted++; } else { $discarded++; print REPORTFILE "<xx> "; print REPORTFILE $line; } } print REPORTFILE "No. of Keywords Converted: "; print REPORTFILE $converted, "\n"; print REPORTFILE "No. of Keywords Discarded: "; print REPORTFILE $discarded, "\n"; close SOURCEFILE or die "Can't close: $!"; close TARGETFILE or die "Can't close: $!"; close REPORTFILE or die "Can't close: $!";
Edited by planetscape - added readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: switching parts of a text
by Tanktalus (Canon) on Sep 14, 2006 at 21:04 UTC | |
by oblate kramrdc (Acolyte) on Sep 14, 2006 at 21:26 UTC | |
|
Re: switching parts of a text
by GrandFather (Saint) on Sep 14, 2006 at 21:26 UTC | |
by oblate kramrdc (Acolyte) on Sep 14, 2006 at 21:36 UTC | |
|
Re: switching parts of a text
by hgolden (Pilgrim) on Sep 14, 2006 at 20:58 UTC |