This file contains hidden or 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
| if ( "test1" =~ /t1/ ) { | |
| say "YES"; | |
| } else { | |
| say "NO" | |
| } | |
| if ( "test2" =~ // ) { | |
| say "YES"; | |
| } else { | |
| say "NO" |
This file contains hidden or 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
| $text =~ m/$re/; | |
| # Такая запись тоже является опасной, поскольку | |
| # переменная $re может содержать пустую строку | |
| # Лучше записывайте так | |
| $text =~ m/(?:$re)/; |
This file contains hidden or 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 @ar = qw/h e l l o/; | |
| foreach (@ar) { | |
| do_something(); | |
| say $_; | |
| } | |
| # Никогда не используйте переменную "$_" | |
| # если в цикле вызывается какая-то внешняя функция. |
This file contains hidden or 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 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 { |
This file contains hidden or 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
| <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> |
This file contains hidden or 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 strict; | |
| use warnings; | |
| use ExtUtils::MakeMaker; | |
| WriteMakefile( | |
| NAME => 'MyApp', | |
| VERSION => 0.01, | |
| MIN_PERL_VERSION => 5.010, | |
| PREREQ_PM => { | |
| 'Mojolicious' => 2.41, |
This file contains hidden or 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
| $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; | |
| } |
This file contains hidden or 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
| package Exception::Base; | |
| use overload | |
| '~~' => sub { $_[0]->isa( $_[1] ) }, | |
| fallback => 1; | |
| package Exception1; | |
| use base 'Exception::Base'; | |
| sub new { bless {}, shift } | |
| package Exception2; |
This file contains hidden or 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
| # ... | |
| 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($) { |
This file contains hidden or 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 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' ); | |