annotate condense_characters.pl @ 0:2c08781560de draft

Uploaded condense_characters tarball.
author devteam
date Tue, 04 Dec 2012 10:53:39 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
1 #! /usr/bin/perl -w
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
2
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
3 use strict;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
4 use warnings;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
5
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
6 # condenses all consecutive characters of one type
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
7 # convert_characters.pl [input] [character] [output]
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
8
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
9 die "Check arguments" unless @ARGV == 3;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
10
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
11 my $inputfile = $ARGV[0];
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
12 my $character = $ARGV[1];
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
13 my $outputfile = $ARGV[2];
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
14
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
15
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
16 my $convert_from;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
17 my $convert_to;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
18
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
19
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
20 if ($character eq "s")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
21 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
22 $convert_from = '\s';
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
23 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
24 elsif ($character eq "T")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
25 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
26 $convert_from = '\t';
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
27 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
28 elsif ($character eq "Sp")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
29 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
30 $convert_from = " ";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
31 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
32 elsif ($character eq "Dt")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
33 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
34 $convert_from = '\.';
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
35 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
36 elsif ($character eq "C")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
37 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
38 $convert_from = ",";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
39 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
40 elsif ($character eq "D")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
41 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
42 $convert_from = "-";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
43 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
44 elsif ($character eq "U")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
45 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
46 $convert_from = "_";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
47 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
48 elsif ($character eq "P")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
49 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
50 $convert_from = '\|';
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
51 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
52 else
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
53 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
54 die "Invalid value specified for convert from\n";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
55 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
56
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
57
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
58 if ($character eq "T")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
59 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
60 $convert_to = "\t";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
61 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
62 elsif ($character eq "Sp")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
63 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
64 $convert_to = " ";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
65 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
66 elsif ($character eq "Dt")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
67 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
68 $convert_to = "\.";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
69 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
70 elsif ($character eq "C")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
71 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
72 $convert_to = ",";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
73 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
74 elsif ($character eq "D")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
75 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
76 $convert_to = "-";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
77 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
78 elsif ($character eq "U")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
79 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
80 $convert_to = "_";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
81 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
82 elsif ($character eq "P")
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
83 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
84 $convert_to = "|";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
85 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
86 else
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
87 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
88 die "Invalid value specified for Convert to\n";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
89 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
90
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
91 my $fhIn;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
92 open ($fhIn, "< $inputfile") or die "Cannot open source file";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
93
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
94 my $fhOut;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
95 open ($fhOut, "> $outputfile");
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
96
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
97 while (<$fhIn>)
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
98 {
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
99 my $thisLine = $_;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
100 chomp $thisLine;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
101 $thisLine =~ s/${convert_from}+/$convert_to/g;
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
102 print $fhOut $thisLine,"\n";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
103 }
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
104 close ($fhIn) or die "Cannot close source file";
2c08781560de Uploaded condense_characters tarball.
devteam
parents:
diff changeset
105 close ($fhOut) or die "Cannot close output file";