1. Perl / Говнокод #5242

    −123

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    my $s = select($rout = $rin, $wout = $win, $eout = $ein, 10);
    
    # ...
    if( !$WORK_DONE) {
              LOG("SLEEP");
              sleep(1);
    }
    $WORK_DONE = 0;

    Высоко нагруженный процесс требующий минимального времени реакции.
    (с) Руслан Залата

    SanityIO, 12 Января 2011

    Комментарии (0)
  2. Perl / Говнокод #5233

    −119

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $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 :)

    SanityIO, 12 Января 2011

    Комментарии (0)
  3. Perl / Говнокод #5231

    −116

    1. 1
    2. 2
    3. 3
    4. 4
    $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)");

    Еще от неизменного автора.

    SanityIO, 12 Января 2011

    Комментарии (2)
  4. Perl / Говнокод #5230

    −118

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    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 от создателя :) Еще (с) Руслан Залата

    SanityIO, 12 Января 2011

    Комментарии (2)
  5. Perl / Говнокод #5229

    −179

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    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 ) ";

    Еще от творца.

    SanityIO, 12 Января 2011

    Комментарии (1)
  6. Perl / Говнокод #5228

    −81

    1. 1
    2. 2
    3. 3
    $search =~ s/[\ \%\*\[\]\^\$\']+/\%/g; # '                                                                                                                                          
    my $search_str = '%' . $search . '%';                                                                                                                                               
    $search_str =~ s/\%+/\%/g;

    эскейп стринга для БД (с) Руслан Залата

    SanityIO, 12 Января 2011

    Комментарии (5)
  7. Perl / Говнокод #5173

    −123

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    # Обработка нажатия клавиш
    # Если нажата кнопка СОХРАНИТЬ
    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'); 
    }

    Из админки одного сайта
    (админка - один сплошной перл)

    happy_me, 07 Января 2011

    Комментарии (13)
  8. Perl / Говнокод #5113

    −122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    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;
    }

    Функция ловеркейзит строку.

    tanenn, 30 Декабря 2010

    Комментарии (6)
  9. Perl / Говнокод #4995

    −117

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    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`;

    LusterDroid, 20 Декабря 2010

    Комментарии (7)
  10. Perl / Говнокод #4798

    −120

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    # 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 автор честно признался, что не знал, как реализовать иначе.

    Anderson, 01 Декабря 2010

    Комментарии (4)