доброго времени суток
перлу знаю плохо просьба помочь
есть допустим файлс некоторым количеством строк
в каждой строке может встречатся допустим слово 0x0
надо вывести на экран количество таких слов иколичество всех остальных
ах да в строках также есть слова типа eth0 и eth1
для каждого из девайсов надо посчитать вышеизложенное
заранее спасибо
#!/usr/local/bin/perl -w
use strict;my ($str, $i, @patterns, @found, @counters, @strings);
@strings = ('0x0', 'eth0', 'eth1');
@patterns = map(qr/$_/, @strings);
@found = ();
@counters = ([0, 0], [0, 0], [0, 0]);open (FILE, 'file.txt') || die "Can't open: $!";
while (defined ($str = <FILE>)) {
for ($i = $#patterns; $i >= 0; $i--) {
($str =~ /$patterns[$i]/) ? ($found[$i] = 1) : ($found[$i] = 0);
} # for
if ($found[0]) {
${$counters[0]}[0]++;
($found[1]) && (${$counters[1]}[0]++);
($found[2]) && (${$counters[2]}[0]++);
} # if
else {
${$counters[0]}[1]++;
($found[1]) && (${$counters[1]}[1]++);
($found[2]) && (${$counters[2]}[1]++);
} # else
} # while
close (FILE);printf ( "\n\n'%s' was found in %i string(s).\n", $strings[0], ${$counters[0]}[0]);
printf ("It was not found in %i string(s).\n", ${$counters[0]}[1]);
print "===========================\n\n";for ($i = $#strings; $i > 0; $i--) {
printf ("There were found %i string(s) that contain both '%s' and '%s'.\n", ${$counters[$i]}[0], $strings[$i], $strings[0]);
printf ("There were found %i string(s) that contain '%s' but don't contain '%s'.\n", ${$counters[$i]}[1], $strings[$i], $strings[0]);
print "===========================\n\n";
} # for