- 1
if ( $method{'out_format'} && $method{'out_format'} eq lc(q{json}) ) {
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−165
if ( $method{'out_format'} && $method{'out_format'} eq lc(q{json}) ) {
Yo dawg, we heard that you like lowercase, so we put some lowercase into your lowercase
−172
sub company_stuff_add_array_elems
{
my $list = shift;
my $count = 0;
foreach ( @$list )
{
$count += $_;
}
return $count;
}
List::Util::sum
http://perldoc.perl.org/List/Util.html
−160
unless( eval{ $p -> role() -> is_company() } or eval{ $p -> channel_status() } or ( $p -> id() eq 11902 ) )
−103
sub exdef {
my ($hash, $key) = @_;
if (exists $hash->{$key} && defined $hash->{$key}) {
return 1;
}
return 0;
}
No comments.
BTW.
http://perldoc.perl.org/functions/exists.html
http://perldoc.perl.org/functions/defined.html
−116
sprintf "%d-%02d-%02d", map { $$_[5]+1900, $$_[4]+1, $$_[3]+1 } [localtime];
Даты. Perl. Классика.
http://perldoc.perl.org/POSIX.html#strftime
−84
use constant MAX_INT => 4294967295;
Code hard.
P.S. perl -MPOSIX -we 'print INT_MAX'
−115
#!/usr/bin/perl -w
use strict;
my $enchant_num=1;
my $tries_num=0;
print "Please, enter safe enchant lvl:\n";
my $safe_enchant_num=<STDIN>; chomp $safe_enchant_num;
print "Please enter maximum enchant lvl:\n";
my $max_enchant_num=<STDIN>; chomp $max_enchant_num;
if($max_enchant_num=~/\d/)
{
if($max_enchant_num>$safe_enchant_num)
{
while($enchant_num<=$max_enchant_num)
{
if($enchant_num<=$safe_enchant_num)
{
while($enchant_num<=$safe_enchant_num)
{
print "Succesfully enchanted for +" . $enchant_num++ . "\r";
}
}
else
{
if(rand(100)<=66)
{
print "Succesfully enchanted for +" . $enchant_num++ . "\r";
}
else
{
print "Enchant failed for +" . $enchant_num++ . "\r";
$enchant_num=1;
$tries_num++;
}
}
}
}
}
else
{
print "\nInput is incorrect\n";
}
print "\nEnchanted for $max_enchant_num with: $tries_num fails.";
Комментарии излишни
−103
# save all blocks to %blocks. Replace first block with <block blockname />
sub _parse_block {
my $tag = $_[1];
last unless $_[0]=~s#($tag->[0]block +([^ /]*?) *$tag->[1])((.*?)$tag->[0]/?block$tag->[1])#
my($opentag,$source,$bname,$bcode, $retval) = ($1,$3, $2, $4, '');
if( $bcode =~m|$tag->[0]block +[^ /]*? *$tag->[1]|){
_parse_block($source, $tag);
$retval = $opentag.$source;
}else{
$retval = "$tag->[0]block $bname /$tag->[1]" unless exists $blocks{$bname};
$bcode=~s%$tag->[0](:? |/)*parent(:? |/)*$tag->[1]%$blocks{$bname}%g;
$blocks{$bname} = $bcode;
}
$retval;
#seg;
}
foreach my $tag( @{$self->{tag_symbols}} ){
_parse_block($code,$tag) while(1);
}
#if <blockmode> turned on, delete all data that not in blocks until </blockmode> or end of code
foreach my $tag( @{$self->{tag_symbols}} ){
$code=~s%$tag->[0] *blocks?(?:mode?)? *$tag->[1](.*?)(?:(?:$tag->[0] *\/ *blocks?(?:mode?)? *$tag->[1])|(';#end of code))%
$_ = $1; my $end_of_code = $2;
my $retval;
$retval .= $1 while( m/($tag->[0]block +[^ ]*? *\/.*?$tag->[1])/g );
$retval.$end_of_code;
%esg;
#
}
# replace <block blockname /> with a code block
foreach my $tag( @{$self->{tag_symbols}} ){
while($code=~s|$tag->[0]block +([A-zА-я0-9_-]*?) */.*?$tag->[1]|$blocks{$1}|eg){};
};
Кусок шаблонизатора. Парсинг вложенных тегов регулярками.
−119
sub merge_data_struct { # to, from, bless coderefs as
for(keys %{$_[1]}){
if(ref($_[1]->{$_}) eq 'HASH'){
merge_data_struct($_[0]->{$_},$_[1]->{$_},$_[2])
}
elsif(ref($_[1]->{$_}) eq 'CODE')
{
warn "Merge datastruct conflict at $_[2] - key $_" if $_[0]->{$_};
$_[0]->{$_} = $_[1]->{$_};
bless ($_[0]->{$_},$_[2]) if($_[2]);
}
else
{
$_[0]->{$_} = $_[1]->{$_};
}
}
}
$_[]{}
−88
% if ($ARGS{standalone_bhv}) {} else {
%# Что-то делаем
% }
Mason. Автор явно знает толк..