This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Getopt::Long; | |
use Data::Dumper; | |
use Locale::gettext; | |
use POSIX(); | |
use Math::Trig; | |
use IO::File; | |
use Time::HiRes qw(gettimeofday); | |
use SDL; | |
use SDL::App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127.0.0.1:5000 | |
Start Time: Wed Apr 13 2011 01:51:13 GMT+0300 (EEST) | |
(P) t=1302648673017 [st= 0] +SOCKET_ALIVE [dt=62501] | |
--> source_dependency = {"id":67944,"type":4} | |
(P) t=1302648673017 [st= 0] +TCP_CONNECT [dt= 1] | |
--> address_list = ["127.0.0.1:5000"] | |
(P) t=1302648673017 [st= 0] TCP_CONNECT_ATTEMPT [dt= 1] | |
--> address = "127.0.0.1:5000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Private accessors/methods | |
# Помещаем ссылку на локальную анонимную функцию в локальную переменную | |
my $name = sub { | |
my $self = shift; | |
... | |
} | |
# Используем как обыкновенный метод, но доступен оно только внутри класса | |
$self->$name(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Private accessors/methods with correct "caller" | |
use Sub::Name; | |
# Помещаем ссылку на локальную анонимную функцию в локальную переменную | |
# и присваиваем ей имя "name" | |
my $name = subname "name" => sub { | |
my $self = shift; | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $rows_affected = $dbh->do('UPDATE ... WHERE') or die; | |
my $rows_affected = $sth->execute(...) or die; # Для не "select" запросов. | |
# $rows_affected может содержать ноль, но быть истинным. | |
# Значит в Perl может быть истинное нулевое значение | |
# И вот несколько вариантов при использовании | |
# которых Perl не сыпет предупреждения | |
"0.0" # Десятичная нотация. Я обычно использую именно этот вариант |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# строка, которая в числовом контексте соответствуют | |
# нулю, а в логическом - истине | |
"0 but true" | |
perl -wE 'say "0 but true"+5' | |
#Получим 5 без никаких предупреждений | |
# Но стоит изменить хоть один символ в заветной строке | |
perl -wE 'say "0 but true!"+5' | |
'Argument "0 but true!" isn't numeric in addition (+) at -e line 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------------------------------------------# | |
# Локализация пакетных переменных | |
our $l = 5; | |
{ | |
local $l = 4; | |
say $l | |
}; | |
say $l; | |
#4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$content = do {local(@ARGV, $/) = $f; <ARGV>} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -e 'while (<ARGV>){ … }' f1 f2 f3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use everywhere 'MooseX::Declare', | |
matching => '^MyApp', | |
use_here => 0; |
OlderNewer