Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Perl使いの国のRubyist

6,353 views

Published on

2018-05-12 RejectKaigi 2018

Published in: Technology
  • Be the first to comment

Perl使いの国のRubyist

  1. 1. 2009 21070 2010 22227 2011 21910 2012 22647 2013 25760 2014 27272 2015 22999 2016 19982 2017 16352 2018 6052 => 17096
  2. 2. Version.group("TO_CHAR(created_at, 'YYYY')").count.sort # => [["2009", 39336], ["2010", 59267], ["2011", 82608], ["2012", 104318], ["2013", 125526], ["2014", 155369], ["2015", 132626], ["2016", 121681], ["2017", 108671], ["2018", 36498]] => 105485
  3. 3. my $array = ["a", "b", "c"]; for (@$array) { print $_ . "n"; } my $array2 = [map { $_ . "foo"; } @$array];
  4. 4. def foo @foo ||= heavy_method end # heavy_method boolean def foo return @foo if defined?(@foo) @foo = heavy_method end
  5. 5. sub foo { shift->{_foo} //= heavy_method }
  6. 6. package Hoge; use parent 'Exporter'; our @EXPORT = qw/foo bar/; sub foo { ... } sub bar { ... }
  7. 7. package Fuga; use Hoge qw/foo/;
  8. 8. # perl reverse uniq grep { $_ ~= /foo/ } <ARGV>; # ruby IO.read(ARGF).lines.grep {|l| l ~/foo/ }.uniq.reverse
  9. 9. sub hoge { my $foo = 'foo'; my $bar = 'bar'; { my $foo = 'baz'; print $foo . $bar . "n"; # => 'bazbar' } print $foo . $bar . "n"; # => 'foobar' }
  10. 10. sub hoge { { # memcached my $guard = Proc::Guard->new(command => ["memcached", "-p", "11211"]); # do something ... } # memcached }
  11. 11. our $foo = 'foo'; sub print_foo { print $foo . "n"; } print_foo; # foo { local $foo = 'bar'; print_foo; # bar } print_foo; # foo
  12. 12. sub foo { my ($num, $str) = @_; print $num . "n"; print $str . "n"; } foo(1, "a");
  13. 13. use Smart::Args::TypeTiny qw(args); sub create { args my $id => 'Id', my $title => 'Str', my $description => 'Maybe[Str]', my $comment => { isa => 'Str', optional => 1 }, # do something... } # hash create( id => 1, title => "title", description => undef, );
  14. 14. my $a = localtime; my @b = localtime; use Data::Dumper; print Dumper $a; # $VAR1 = 'Fri May 4 16:14:45 2018'; print Dumper @b; # $VAR1 = 45; # $VAR2 = 14; # $VAR3 = 16; # $VAR4 = 4; # $VAR5 = 4; # $VAR6 = '118'; # $VAR7 = 5; # $VAR8 = 123;
  15. 15. sub foo { print @_ . 'n'; } my $method_name = 'foo'; { # no strict 'refs'; &{$method_name}('bar'); }
  16. 16. 5.027009 => { delta_from => 5.027008, changed => { 'B::Op_private' => '5.027009', ... # 140 'warnings' => '1.41', }, removed => { 'Module::CoreList::TieHashDelta'=> 1, } }, 5.027010 => { delta_from => 5.027009, changed => { 'App::Prove' => '3.42', ... # 193

×