--- nfo/perl/libs/shortcuts/files.pm 2003/02/20 21:12:24 1.2 +++ nfo/perl/libs/shortcuts/files.pm 2003/03/31 05:47:01 1.3 @@ -1,7 +1,10 @@ ## --------------------------------------------------------------------------- -## $Id: files.pm,v 1.2 2003/02/20 21:12:24 joko Exp $ +## $Id: files.pm,v 1.3 2003/03/31 05:47:01 janosch Exp $ ## --------------------------------------------------------------------------- ## $Log: files.pm,v $ +## Revision 1.3 2003/03/31 05:47:01 janosch +## Mis mif gex +## ## Revision 1.2 2003/02/20 21:12:24 joko ## + prints to STDERR if logfile could not be opened ## @@ -10,6 +13,17 @@ ## ## --------------------------------------------------------------------------- +=pod + +=head1 Background + + UNIX = Everything is a file + Perl ~ Everything is a string ;-) + + +=cut + + package shortcuts::files; @@ -22,6 +36,8 @@ s2f a2f f2s + rif + mif ); @@ -106,6 +122,52 @@ s2f($outfile, $buf); } +sub mis { + my $string = shift; + my $rules = shift; + + my $mis_result = {}; + + if (ref $rules eq 'HASH') { + my @re_find = keys %{$rules}; + # replace all keys with substitutes from hash "%re_table" + foreach my $find (@re_find) { + #my $replace = $rules->{$find}; + #$mis_result &= ($string =~ m/$find/g); + $mis_result->{$find} = ($string =~ m/$find/g); + $mis_result->{$find} ||= 0; + } + } + + if (ref $rules eq 'ARRAY') { + foreach my $rule (@{$rules}) { + my $find = (ref $rule eq 'ARRAY') ? $rule->[0] : $rule; + $mis_result->{$find} = 0; + my $pattern = quotemeta($find); + $string =~ s{ + $pattern # the pattern used to search through the whole file + }{ + $mis_result->{$find}++; # build result (increase counter per occourance) + }gex; + } + } + + return $mis_result; +} + +sub mif { + my $filename = shift; + my $rules = shift; + my $out_suffix = shift; + + my $outfile = $filename; + $outfile .= '.' . $out_suffix if ($out_suffix); + + my $buf = f2s($filename); + return mis($buf, $rules); + #s2f($outfile, $buf); +} + sub findKeyEntries { my $string = shift; my $pattern = shift;