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

    −108

    1. 1
    push @sqls, defined($result->{sql}) ? $result->{sql} : return;

    Не знаю, что тут написать. Сегодня это встретил в коде.

    Elvenfighter, 13 Сентября 2012

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

    −154

    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
    sub makeCleanString {
            my ($self, $uncleanString) = @_;
            $uncleanString = lc($uncleanString);
            my @allowedChars = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "@", ".", " ");     
                 
             my $cleanString = "";
                 
             # SPLIT THE uncleanString INTO AN ARRAY
             my @usernameAR = split(//, $uncleanString);
             my $usernameARcount = @usernameAR;
             my $run=0;
             for ($run=0;$run<$usernameARcount;$run++) {
                 if(grep $_ eq $usernameAR[$run], @allowedChars) {
                     $cleanString .= $usernameAR[$run];
                 }
             }
             return $cleanString;
        }

    Так же есть подобные методы только для букв и цифр

    LiteError, 09 Сентября 2012

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

    −139

    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
    #!/usr/bin/perl -w
    
    use strict;
    use warnings;
    use diagnostics;
    use LWP::Simple;
    
    binmode(STDOUT, ":utf8");
    
    my $url = 'http://govnokod.ru/comments';
    my $document = get $url;  die "Couldn't get $url" unless defined $document;
    $document =~ s/\n/ /g;
    $document =~ s/\h+/ /g;
    my @arr = ( $document =~ m/(?<=\<strong class="entry-author">)(.*?)(?<=\<a class="answer")/gi );
    my $str;
    my @sink;
    
    foreach my $val (@arr) {
    	$val =~ m/(?<=\>)(.*?)(?=\<\/a\>)/i;
    	$str = "Author:    ".$1;
    	$val =~ m/(?<=published" title\=")(.*?)(?=")/i;
    	( my $dt, my $tm ) = split('T', $1);
    	$str = $str . "\nDate:      " . $dt;
    	$str = $str . "\nTime:      " . $tm;
    	$val =~ m/(?<=\<\/abbr\> \<a href\=")(.*?)(?=" name\=)/i;
    	$str = $str."\nLink:      ". $1;
    	$val =~ m/(?<=\<div class\="entry-comment">)(.*?)(?=\<\/div\>)/i;
    	$str = $str . "\nComment:   " . str_formater($1);
    	push(@sink, $str);
    }
    
    @sink = reverse (@sink);
    foreach my $v (@sink) {
    	print ("\n".("+" x 81)."\n"."$v\n");
    }
    print ("\n".("+" x 81)."\n\n");
    
    sub str_formater {
    	my $str = $_[0];
    	my $res="";
    	my $cmt_len = 69;
    	my $cmt_indent = 11;
    	while (1) {
    		if (length($str)<=$cmt_len) {
    			return $res . $str;
    		}
    		$res = $res . substr($str,0, $cmt_len) . "\n" . (" " x $cmt_indent);
    		$str = substr($str, $cmt_len);
    	}
    	return $res;
    }
    exit 0;

    Давненько перловку не заваривал...

    sayidandrtfm, 06 Августа 2012

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

    −136

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    sub parse_http_date($)
    {
    	my ($date)=@_;
    	my %months=(Jan=>0,Feb=>1,Mar=>2,Apr=>3,May=>4,Jun=>5,Jul=>6,Aug=>7,Sep=>8,Oct=>9,Nov=>10,Dec=>11);
    
    	if($date=~/^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$/)
    	{ return eval { timegm($6,$5,$4,$1,$months{$2},$3-1900) } }
    
    	return undef;
    }

    Вакаба.

    7ion, 28 Июля 2012

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

    −133

    1. 1
    return { map { $_ => $domain->$_ } qw( name ) };

    Мини-говнокодик. Ради одного имени наворотили map.

    ichesnokov, 23 Июля 2012

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

    −125

    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
    if ($f_ISSUE_DATE !~ /^\d\d.\d\d.\d\d\d\d/ && $f_ISSUE_DATE){
                    $e_ISSUE_DATE = 'Дата выдачи паспорта вводится в формате "ДД.ММ.ГГГГ"';
                    $errorCounter ++;
            }
            if ($f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(ул\.)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(бул\.)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(наб\.)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(пер\.)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(пл\.)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(пр\.)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(просп\.)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*(шоссе)\s*(.*)$/ &&
            $f_ADDRESS_OF_SVC_SHOP !~ /^(\w+)\s+(.+?),\s*()\s*(.*)$/)        {
                    $e_ADDRESS_OF_SVC_SHOP = 'Неправильный формат фактического адреса';
                    $errorCounter ++;
            }

    Ебаный стыд!!!
    скопипасчено из попавшегося куска "исподников", идет прям подряд.
    Уж даже и не знаю - что больший пиздец - первая часть или вторая.

    PS. Для тех кто вел себя хорого - конфетка!
    ВЕСЬ, БЛЯДЬ, проект постоен без единого гвозьдя!!! НИ ОДИН объект не пострадал!!!

    Meettya, 05 Июля 2012

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

    −124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    > cat 1.pl
    $owner = "Jack";
    print "This is $owner\n";
    print "This is $owner's house\n";
    >  perl 1.pl
    This is Jack
    This is  house

    The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it's more readable to humans, and in part because it's more readable to emacs macros. It also makes C++ programmers feel like they know what's going on--as opposed to using the single quote as separator, which was there to make Ada programmers feel like they knew what was going on. Because the old-fashioned syntax is still supported for backwards compatibility, if you try to use a string like "This is $owner's house" , you'll be accessing $owner::s ; that is, the $s variable in package owner , which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house" .

    bormand, 21 Июня 2012

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

    −104

    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 ($key eq $default_key){
    		my $author = $default_author;
    		if ($release){
    			if (length $release <= $max_release){
    				if (length $description <= $max_description){			
    					if ($filename){
    						if (clearfn(\$filename) eq 1){
    							if (! -e "$files_dir/$filename"){
    								$release = clear($release);
    								$description = clear($description);
    								$description = bb($description);
    								open FILE, '>>db.txt' or die $!;
    								print FILE "$release\t$filename\t$description\t$author\t" . ftime() . "\n";
    								close FILE;
    								open FILE, ">$files_dir/$filename" or die "$!";
    								binmode FILE;
    								while (<$filehandle>){
    									print FILE;
    								}
    								close FILE;
    								$result = 'Файл успешно добавлен!';
    								rss();
    							}
    							else {
    								$result = 'Ошибка: Файл с таким именем уже загружен!';
    							}
    						}
    						else {
    							$result = 'Ошибка: Недопустимое расширение файла!';
    						}
    					}
    					else {
    						$result = 'Ошибка: Нет файла!';
    					}
    				}
    				else {
    					$result = "Ошибка: В описании должно быть не более $max_description символов!";
    				}
    			}
    			else {
    				$result = "Ошибка: В названии должно быть не более $max_release символов!";
    			}
    		}
    		else {
    			$result = 'Ошибка: Нет названия!';
    		}
    	}
    	else {
    		$result = 'Ошибка: ';
    	}

    Писал паскалеребенок

    nyaknyan, 14 Июня 2012

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

    −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
    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
    #!/usr/bin/perl
    use strict;
    
    # немного настроек
    my $url = "http://govnokod.ru/comments";
    my $min_delay = 2*60;
    my $max_delay = 30*60;
    my $delay_slowdown = 2;
    
    # получение идентификатора последнего коммента
    sub get_last_comment_info {
        print STDERR "Checking for the new comments...\n";
        my @content = `curl "$url" 2>/dev/null`;
        my $s = join(' ', @content);
        if ($s =~ /<a href=".*?\/(\d+)#comment(\d+)"/) {
            print STDERR "Last comment id was $2 in the thread $1\n";
            return ("thread" => $1, "comment" => $2);
        }
        print "Can't get new comments\n";
        return ();
    }
    
    # отправка сообщения
    sub notify {
        my ($id) = @_;
        print STDERR "Sending notify about $id\n";
        `notify-send "Кто-то наложил в $id"`;
    }
    
    my $last_id = undef;
    my $delay = $min_delay;
    while (1) {
        # смотрим есть ли новый коммент
        if (my %r = get_last_comment_info()) {
            if (defined($last_id) && $r{"comment"} > $last_id) {
                $delay = $min_delay;
                notify($r{"thread"});
            }
            $last_id = $r{"comment"};
        }
        # спим
        print STDERR "Sleeping for $delay seconds...\n";
        sleep($delay);
        # пересчитываем задержку
        $delay = $delay * $delay_slowdown;
        $delay = $max_delay if ($delay > $max_delay);
    }

    Говноскрипт для мониторинга сточных вод.

    bormand, 27 Мая 2012

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

    −122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    my (@data) = $content =~ m#href="/show/\d+.*?">(.*?)</a>.*?(Ep: \d+).*?(at \d{2}:\d{2}).*?</small>#gsi;
    	
    for (my $i; $i < @data;){
    	$data .= $data [$i++].' '.$data [$i++].' '.$data [$i++];
    	$data .= "\n" unless $i == @data;
    }

    Распарсил.

    VictorVonSpok, 21 Мая 2012

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