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.

Okinawapm #1

294 views

Published on

Okinawapm #1

Published in: Engineering
  • Be the first to comment

Okinawapm #1

  1. 1. PerlとCと時々Python @CodeHex
  2. 2. 自己紹介 • 本名: 上川 慶 • R大3年 • Perl大好き • OS大好き • 最近は自然言語処理に興味あ り • エイサーやってます
  3. 3. CとPerlが似てるよね
  4. 4. 例えば
  5. 5. #!/usr/bin/env perl use strict; use warnings; print("Hello, Worldn"); #include <stdio.h> int main() { printf("Hello, Worldn"); } C Perl 結果 Hello, World printfとprint
  6. 6. あれ print 文が違う?
  7. 7. 実は
  8. 8. PerlでもCの関数が使える
  9. 9. #!/usr/bin/env perl use strict; use warnings; for (my $i = 0; $i < 10; $i++) { printf(“%d ", $i); } #include <stdio.h> int main() { for (int i = 0; i < 10; ++i) { printf(“%d ", i); } } C Perl 結果 0 1 2 3 4 5 6 7 8 9 for
  10. 10. #!/usr/bin/env perl use strict; use warnings; my $i = 0; while ($i++ < 10) { printf("%d ", $i); } #include <stdio.h> int main() { int i = 0; while (i++ < 10) { printf("%d ", i); } } C Perl 結果 1 2 3 4 5 6 7 8 9 10 while
  11. 11. #!/usr/bin/env perl use strict; use warnings; my $i = 0; do { printf("%d ", $i); } while ($i++ < 10); #include <stdio.h> int main() { int i = 0; do { printf("%d ", i); } while (i++ < 10); } C Perl 結果 0 1 2 3 4 5 6 7 8 9 10 do while
  12. 12. すごい似てる!!
  13. 13. #!/usr/bin/env perl use strict; use warnings; my $i = 0; if ($i == 0) { printf("Matched %d == 1n", $i); } elsif ($i == 1) { printf("Matched %d == 1n", $i); } else { printf("Not Matchedn"); } #include <stdio.h> int main() { int i = 0; if (i == 0) { printf("Matched %d == 1n", i); } else if (i == 1) { printf("Matched %d == 1n", i); } else { printf("Not Matchedn"); } } C Perl 結果 Matched 0 == 1 if
  14. 14. C だと else if Perl だと elsif
  15. 15. #!/usr/bin/perl use strict; use warnings; my $i = 0; $i == 0 ? printf("Matched %d == 1n", $i) : $i == 1 ? printf("Matched %d == 1n", $i) : printf("Not Matchedn"); #include <stdio.h> int main() { int i = 0; i == 0 ? printf("Matched %d == 1n", i) : i == 1 ? printf("Matched %d == 1n", i) : printf("Not Matchedn"); } C Perl 結果 Matched 0 == 1 三項演算子
  16. 16. #!/usr/bin/env perl use strict; use warnings; use Switch; my $i = 0; switch ($i) { case 0 { printf("Matched %d == 1n", $i); last; } case 1 { printf("Matched %d == 1n", $i); last; } else { printf("Not Matchedn”); last; } } #include <stdio.h> int main() { int i = 0; switch (i) { case 0: printf("Matched %d == 1n", i); break; case 1: printf("Matched %d == 1n", i); break; default: printf("Not Matchedn”); break; } } C Perl 結果 Matched 0 == 1 switch
  17. 17. Perl には given 文がありますが、 そこは割愛しますm(_ _)m
  18. 18. PythonとPerl
  19. 19. #!/usr/bin/env perl use strict; use warnings; my @l = (0, 1, 2, 3, 4, 5); foreach my $i (@l) { printf("%d ", $i); } #!/usr/bin/env python l = [0, 1, 2, 3, 4, 5] for i in l: print("%d " % i, end="") Python Perl 結果 0 1 2 3 4 5 for in と foreach
  20. 20. 若干似てる(笑)
  21. 21.
  22. 22.
  23. 23. まとめ • CとPerlは文法的に似ている • Perlで一部のCの関数が使える • Perlで使える関数のほとんどはPythonでも使える関 数である <- New
  24. 24. Perlを極めると大体の言語使え る!!
  25. 25. ご静聴ありがとうございました

×