- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
my $s = select($rout = $rin, $wout = $win, $eout = $ein, 10);
# ...
if( !$WORK_DONE) {
LOG("SLEEP");
sleep(1);
}
$WORK_DONE = 0;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−123
my $s = select($rout = $rin, $wout = $win, $eout = $ein, 10);
# ...
if( !$WORK_DONE) {
LOG("SLEEP");
sleep(1);
}
$WORK_DONE = 0;
Высоко нагруженный процесс требующий минимального времени реакции.
(с) Руслан Залата
−119
$max_conn = 150;
# ...
socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) || LOG_FLUSH && die "socket: $!";
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) || LOG_FLUSH && die "setsockopt: $!";
bind(SERVER, sockaddr_in($port, inet_aton($interface))) || LOG_FLUSH && die "bind: $!";
listen(SERVER,$max_conn) || LOG_FLUSH && die "listen: $!";
Перл от создателя. $max_conn - это якобы должно быть максимальное число дочерних процессов (причем количество child процессов не проверяется). хотя все знаю что должно передаваться как аргумент backlog :)
−116
$answer=~ s/\\/\\\\/g;
$answer=~ s/\'/\\\'/g;
# ...
$dbh->do("INSERT INTO docflow_rules (type_,state1,state2,p,entity,subj_require,comm_require) VALUES ($doctype,$from_,$to_,'$answer',$entity,$subj_r,$comm_r)");
Еще от неизменного автора.
−118
if(
( $session_begin ge $tariff_ref->{date} ) &&
( !$tariff_ref->{date_end} || $session_begin le $tariff_ref->{date_end} ) &&
( !$tariff_ref->{nas_id} || $tariff_ref->{nas_id} eq $nas_id) &&
( !$tariff_ref->{ppp_type} || $tariff_ref->{ppp_type} eq $ppp_type) &&
( $notariffzone || !$tariff_ref->{tariff_zone} ||
$tariff_ref->{tariff_zone} eq $tariff_zone) &&
( !$tariff_ref->{client_type} || $tariff_ref->{client_type} eq $client_type) &&
( !$tariff_ref->{day_type} || $tariff_ref->{day_type} eq
&common::type_of_day($oper_id,$session_begin) ) &&
(
(!$divide_by_time_zone &&
(!$tariff_ref->{time_from} || !$tariff_ref->{time_to} ||
&common::check_time_zone(
$session_begin,
$tariff_ref->{time_from},
$tariff_ref->{time_to}
)
)
) ||
($divide_by_time_zone &&
(!$tariff_ref->{time_from} || !$tariff_ref->{time_to} ||
&common::check_time_zone(
$session_begin,
$tariff_ref->{time_from},
$tariff_ref->{time_to}
) ||
&common::check_time_zone(
$session_end,
$tariff_ref->{time_from},
$tariff_ref->{time_to}
) ||
&common::check_time_zone(
$tariff_ref->{time_from},
common::get_time_from_str($session_begin),
common::get_time_from_str($session_end),
)
)
)
) &&
(
(!$divide_by_counter &&
(!defined($tariff_ref->{counter1_from}) || !defined($tariff_ref->{counter1_to})
|| ($tariff_ref->{counter1_from} <= $resource_begin &&
$resource_begin < $tariff_ref->{counter1_to} )
)
) ||
($divide_by_counter &&
(!defined($tariff_ref->{counter1_from}) || !defined($tariff_ref->{counter1_to})
|| ($tariff_ref->{counter1_from} <= $resource_begin &&
$resource_begin < $tariff_ref->{counter1_to} )
|| ($tariff_ref->{counter1_from} <= $resource_end &&
$resource_end < $tariff_ref->{counter1_to} )
|| ($resource_begin <= $tariff_ref->{counter1_from} &&
$tariff_ref->{counter1_from} < $resource_end)
)
)
)
) {
Один if от создателя :) Еще (с) Руслан Залата
−179
if (! $where_oper_id ) {
$where_oper_id = " base_clients.oper_id = 'THERE IS NO FUCKING PROVIDERS DEFINED FOR THIS OPERATOR' " ;
$where_service_oper_id = " oper_id = 'THERE IS NO FUCKING PROVIDERS DEFINED FOR THIS OPERATOR' " ;
}
$where_oper_id = " ( $where_oper_id ) ";
Еще от творца.
−81
$search =~ s/[\ \%\*\[\]\^\$\']+/\%/g; # '
my $search_str = '%' . $search . '%';
$search_str =~ s/\%+/\%/g;
эскейп стринга для БД (с) Руслан Залата
−123
# Обработка нажатия клавиш
# Если нажата кнопка СОХРАНИТЬ
if(CGI::param('sub_data_save'))
{
if(CGI::param('content')){ $content=CGI::param('content'); }
$content=~s/'/\\'/g;
$dbh->do("update public.m_content set content='$content' where id=70");
# Зафиксировали изменения
$dbh->commit;
# формируем страницу
md::tools->create_page($www{'main_template'},"<#CONTENT#>",$content,$www{'path'},'/turfirm.php');
# подгонка остальных страниц
# новости
$sql = "select content from public.m_content where \"id\"=20";
$sth=$dbh->prepare($sql);
$sth->execute;
($content0)=$sth->fetchrow_array;
md::tools->create_page($www{'main_template'},"<#CONTENT#>",$content0,$www{'path'},'/news.php');
# Корпаративным клиентам
$sql = "select content from public.m_content where \"id\"=60";
$sth=$dbh->prepare($sql);
$sth->execute;
($content0)=$sth->fetchrow_array;
md::tools->create_page($www{'main_template'},"<#CONTENT#>",$content0,$www{'path'},'/cor_clients.php');
# Главная
$sql = "select content from public.m_content where \"id\"=10";
$sth=$dbh->prepare($sql);
$sth->execute;
($content0)=$sth->fetchrow_array;
md::tools->create_page($www{'main_template'},"<#CONTENT#>",$content0,$www{'path'},'/index.php');
# Контакты
$sql = "select content from public.m_content where \"id\"=30";
$sth=$dbh->prepare($sql);
$sth->execute;
($content0)=$sth->fetchrow_array;
md::tools->create_page($www{'main_template'},"<#CONTENT#>",$content0,$www{'path'},'/contact.php');
# Базы
$sql = "select content from public.m_content where \"id\"=40";
$sth=$dbh->prepare($sql);
$sth->execute;
($content0)=$sth->fetchrow_array;
md::tools->create_page($www{'main_template'},"<#CONTENT#>",$content0,$www{'path'},'/centre.php');
# Бронирование
$content0="<iframe width=100% scrolling='auto' height=100% frameborder=0 src='/cgi-bin/res.cgi' ></iframe>";
md::tools->create_page($www{'main_template'},"<#CONTENT#>",$content0,$www{'path'},'/reservation.php');
}
Из админки одного сайта
(админка - один сплошной перл)
−122
sub translateToSearch {
my($search)=@_;
$search =~ s/\ /\*/g;
my $s_up=to_upper($search);
my $s_low=to_lower($search);
my $s="";
my $last_s="";
for($i=0;$i<length($search);$i++) {
my $ch=substr($search,$i,1);
if(!($ch eq "*")) {
$s.="[".substr($s_up,$i,1).substr($s_low,$i,1)."]";
} elsif( !($last_s eq "*")) {
$s.=".*";
}
$last_s=$ch;
}
return $s;
}
Функция ловеркейзит строку.
−117
my $result = `zabbix_agent -t proc.num[,,,*.pl]`
...
#удаляем файлы форков
`rm /tmp/event_agent_fork_*`;
`rm /tmp/event_agent_main_*`;
...
`killall -9 event_agent.pl`;
sleep(5);
`/usr/local/blabla/bin/blabla.pl`;
−120
# Find out what mail program to use !! Terrible kludge !!
$mailprogram = "/usr/bin/mail";
if (! -x "$mailprogram") {
if (-x "/bin/mail") {
$mailprogram = "/bin/mail";
} else {
if (-x "/usr/sbin/sendmail") {
$mailprogram = "/usr/sbin/sendmail";
} else {
if (-x "/usr/lib/sendmail") {
$mailprogram = "/usr/lib/sendmail";
} else {
if (-x "/usr/bin/mutt") {
$mailprogram = "/usr/bin/mutt";
} else {
if (-x "/usr/sbin/exim4") {
$mailprogram = "/usr/sbin/exim4";
} else {
if (-x "/usr/bin/elm") {
$mailprogram = "/usr/bin/elm";
} else {
print "Cannot find a mail program to use\n";
}
}
}
}
}
}
}
В changelog автор честно признался, что не знал, как реализовать иначе.