Анимация
JavaScript


Главная  Библионтека 

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 [ 72 ] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

If ($opt{p} II $opt{P}) {

patterns = map patterns;

$opt{p} && ($/ = );

$opt{P} && ($/ = eval(qqC$opt{P}-))); # for -P •%%\n $opt{w} && (patterns = map {\b . $ . ЛЬ} patterns); $opt{x} && (©patterns = map {""S.VS"} ©patterns); If (@ARGV) {

$Mult = 1 If ($opt{r} 11 (@ARGV > 1) II -d $ARGV[0]) && !$opt{h},

$opt{1} += $opt{l}; # Единица и буква 1

$opt{H} += $opt{u}; $opt{c> += $opt{C}; SoptCs} += $opt{c);

$opt{1} += $opt{-s} && !$opt{c}, # Единица

@ARGV = ($opt{r} . : -) unless @ARGV;

$opt{r) = 1 If i$opt<r} && grep(-d, @ARGV) == @ARGV;

$match code = ;

$match code = study; if ©patterns > 5; # Может немного

# ускорить работу

foreach (patterns) { s(/)(\\/)g }

If ($opt{H}) {

foreach Spattern (patterns) {

$match code = "XSMatches += s/(Spattern)/S<S0}\$1${SE>/g, ;

elsif ($opt{v}) {

foreach Spattern (©patterns) {

Smatch code .= "\SMatches += !/Spattern/,;

>

elsif (Sopt{C>) i

foreach Spattern (patterns) {

Smatch code = \SMatches++ while /Spattern/g;";

else {

foreach Spattern (patterns) {

$fflatch code = "\SMatches++ if /Spattern/;";



234 Глава 6 • Поиск по шаблону Пример 6.14 (продолжение)

Smatcher = eval "sub { $match code }"; die if $@;

return (\%opt, Smatcher);

«#«####«#####«####################«

sub matchfile {

Sopt = shift; Й Ссылка на хэш параметров

Smatcher = shift; й Ссылка на функцию поиска совпадений

ту (Sfile. ©list, Stotal, Sname);

local($ );

Stotal = 0;

FILE: while (defined (Sfile = shift(© ))) <

if (-d Sfile) {

if (-1 Sfile && ©ARGV != 1) {

warn "SMe: \"$file\" is a symlink to a directory\n"

if $opt->{T}; next FILE;

if (!$opt->{r}) {

warn "SMe; \"$file\" is a directory, but no -r given\n"

if $opt->{T}; next FILE;

unless (opendir(DIR, Sfile)) { unless ($opt->{q}) {

warn "SMe: cant opendir Sfile: S!\n"; $Errors++;

next FILE;

©list = 0;

for (readdir(DIR)) {

push(©list, "$file/$ ") unless /"\.(1,2}$/;

closedir(DIR); if ($opt->{t}) { my (©dates);

for (©list) { push(©dates, -M) }

©list = @list[sort { $dates[Sa] <=> Sdates[$b] } 0..Sedates];

else <

©list = sort ©list;



matchfile($opt, Smatcher, @list); й process files next FILE;

if (Sfile eq -) {

warn "SMe: reading from stdin\n" if -t STDIN && !Sopt->{q}; Sname = <STDIN>;

else {

Sname = Sfile; unless (-e Sfile) {

warn qq($Me: file "Sfile" does not exist\n)

unless Sopt->{q}; SErrors++; next FILE;

unless (-f Sfile $opt->{a}) {

warn qq(SMe: skipping non-plain file "Sfile"\n)

if Sopt->{T}; next FILE;

my (Sext) = Sfile =" /\.([".]+)S/; if (defined Sext && exists SCompress{Sext}) { Sfile = "SCompress{Sext} <Sfile 1";

elsif (! (-T Sfile $opt->{a})) {

warn qq($Me: skipping binary file "Sfile"\n) if Sopt->{T}; next FILE;

warn "SMe: checking Sfile\n" if Sopt->{T};

unless (open(FILE, Sfile)) { unless ($opt->{q}) {

warn "SMe; Sfile: S!\n"; SErrors++;

next FILE;

Stotal = 0;

SMatches = 0;

LINE: while (<FILE>) { SMatches = 0;



0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 [ 72 ] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242