2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.3 2003/03/31 05:47:01 janosch |
6 |
|
## Mis mif gex |
7 |
|
## |
8 |
## Revision 1.2 2003/02/20 21:12:24 joko |
## Revision 1.2 2003/02/20 21:12:24 joko |
9 |
## + prints to STDERR if logfile could not be opened |
## + prints to STDERR if logfile could not be opened |
10 |
## |
## |
13 |
## |
## |
14 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
15 |
|
|
16 |
|
=pod |
17 |
|
|
18 |
|
=head1 Background |
19 |
|
|
20 |
|
UNIX = Everything is a file |
21 |
|
Perl ~ Everything is a string ;-) |
22 |
|
|
23 |
|
|
24 |
|
=cut |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
package shortcuts::files; |
package shortcuts::files; |
29 |
|
|
36 |
s2f |
s2f |
37 |
a2f |
a2f |
38 |
f2s |
f2s |
39 |
|
rif |
40 |
|
mif |
41 |
); |
); |
42 |
|
|
43 |
|
|
122 |
s2f($outfile, $buf); |
s2f($outfile, $buf); |
123 |
} |
} |
124 |
|
|
125 |
|
sub mis { |
126 |
|
my $string = shift; |
127 |
|
my $rules = shift; |
128 |
|
|
129 |
|
my $mis_result = {}; |
130 |
|
|
131 |
|
if (ref $rules eq 'HASH') { |
132 |
|
my @re_find = keys %{$rules}; |
133 |
|
# replace all keys with substitutes from hash "%re_table" |
134 |
|
foreach my $find (@re_find) { |
135 |
|
#my $replace = $rules->{$find}; |
136 |
|
#$mis_result &= ($string =~ m/$find/g); |
137 |
|
$mis_result->{$find} = ($string =~ m/$find/g); |
138 |
|
$mis_result->{$find} ||= 0; |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
if (ref $rules eq 'ARRAY') { |
143 |
|
foreach my $rule (@{$rules}) { |
144 |
|
my $find = (ref $rule eq 'ARRAY') ? $rule->[0] : $rule; |
145 |
|
$mis_result->{$find} = 0; |
146 |
|
my $pattern = quotemeta($find); |
147 |
|
$string =~ s{ |
148 |
|
$pattern # the pattern used to search through the whole file |
149 |
|
}{ |
150 |
|
$mis_result->{$find}++; # build result (increase counter per occourance) |
151 |
|
}gex; |
152 |
|
} |
153 |
|
} |
154 |
|
|
155 |
|
return $mis_result; |
156 |
|
} |
157 |
|
|
158 |
|
sub mif { |
159 |
|
my $filename = shift; |
160 |
|
my $rules = shift; |
161 |
|
my $out_suffix = shift; |
162 |
|
|
163 |
|
my $outfile = $filename; |
164 |
|
$outfile .= '.' . $out_suffix if ($out_suffix); |
165 |
|
|
166 |
|
my $buf = f2s($filename); |
167 |
|
return mis($buf, $rules); |
168 |
|
#s2f($outfile, $buf); |
169 |
|
} |
170 |
|
|
171 |
sub findKeyEntries { |
sub findKeyEntries { |
172 |
my $string = shift; |
my $string = shift; |
173 |
my $pattern = shift; |
my $pattern = shift; |