Skip to content

Instantly share code, notes, and snippets.

View koorchik's full-sized avatar
🇺🇦

Viktor Turskyi koorchik

🇺🇦
View GitHub Profile
if ( "test1" =~ /t1/ ) {
say "YES";
} else {
say "NO"
}
if ( "test2" =~ // ) {
say "YES";
} else {
say "NO"
$text =~ m/$re/;
# Такая запись тоже является опасной, поскольку
# переменная $re может содержать пустую строку
# Лучше записывайте так
$text =~ m/(?:$re)/;
# Опасный код!!!
my @ar = qw/h e l l o/;
foreach (@ar) {
do_something();
say $_;
}
# Никогда не используйте переменную "$_"
# если в цикле вызывается какая-то внешняя функция.
use v5.10;
use Sub::Name;
my $name1 = subname name1 => sub {
say( (caller(0))[3] );
say( (caller(1))[3] );
say( (caller(2))[3] );
};
my $name2 = subname name2 => sub {
<meta name="csrftoken" content="af58af65a8f65a8dfafa76df8a7afdf"/>
<script type="text/javascript">
$(document).ajaxSend(function(e, xhr, options) {
var token = $("meta[name='csrftoken']").attr("content");
xhr.setRequestHeader("X-CSRF-Token", token);
})
</script>
@koorchik
koorchik / Makefile.PL
Created January 5, 2012 16:51
Makefile example
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'MyApp',
VERSION => 0.01,
MIN_PERL_VERSION => 5.010,
PREREQ_PM => {
'Mojolicious' => 2.41,
@koorchik
koorchik / render_file.pl
Created May 15, 2012 05:38
render_file
$app->helper('render_file' => sub {
my $c = shift;
my %args = @_;
my $filepath = $args{filepath};
unless ( -f $filepath && -r $filepath ) {
$c->app->log->error("Cannot read file [$filepath]. error [$!]");
return;
}
@koorchik
koorchik / try_tiny_dispatch_exceptions.pl
Created May 19, 2012 07:58
Try::Tiny dispatch exceptions
package Exception::Base;
use overload
'~~' => sub { $_[0]->isa( $_[1] ) },
fallback => 1;
package Exception1;
use base 'Exception::Base';
sub new { bless {}, shift }
package Exception2;
@koorchik
koorchik / try_tiny_with_helper.pl
Created May 19, 2012 08:02
Try::Tiny with helper
# ...
test_exception( Exception1->new() );
test_exception( Exception2->new() );
test_exception( Exception3->new() );
test_exception("Special text\n");
test_exception("Text exception\n");
use Scalar::Util qw/blessed/;
sub e($) {
@koorchik
koorchik / list_util_bug.pl
Created June 2, 2012 11:26
List::Util::first bug
use List::Util qw/first/;
use List::MoreUtils qw/first_value/;
use v5.10;
use Test::More;
is( test('grep'), 4, 'Grep for finding first value' );
is( test('list_util'), 4, 'List::Util::first for finding first value' );
is( test('list_more_utils'), 4, 'List::MoreUtils::first_value for finding first value' );