Mihyaeru
June 11, 2014
150

# Gotanda.pm #1

Python使いから見たPerl @ Gotanda.pm #1

June 11, 2014

## Transcript

2. ### ࣗݾ঺հ w ϛώϟΤϧ!NJIZBFSV w 1ZUIPO 0CKFDUJWF\$ śƂŠƃٙ࿭   1FSM w

ΏͱΓ7JNNFS w ζϰΟζμʔઓಆһ

\$name\n"; }

7. ### sub sum_numbers { my \$sum; for (@_) { \$sum +=

\$_; } ! return \$sum; }

11. ### ࠷ॳʹࢥͬͨෆຬ w มͳه߸ଟͯ͘ҙຯෆ໌ w ίϯςΩετʁʁʁ w ຖճNZͬͯॻ͘ͷ໘౗͍͘͞ w ਅِ஋Σʜʜ w

ϦϑΝϨϯεपΓ͕Θ͔Γʹ͍͘ w Ҿ਺Ϧετ͸Ͳ͜ʂʁ ʜଞʹ΋͔͋ͬͨ΋͚ͩͲ๨Εͨ͆

13. ### ͜Μ͖ͯ͢ͱʁʁʁ @a = (0, 1, 2) Ϧετ  ίϯςΩετ 0, 1,

2 εΧϥʔ  ίϯςΩετ 3 ཁૉ਺͕஌Γ͔ͨͬͨΒlen()ͱ͔໌ࣔతʹॻ͖͍ͨ ৔ॴʹΑͬͯҙຯ͢Δͱ͜Ζ͕ҧ͏ʜʜͩͱʜʜ

16. ### ϦϑΝϨϯε w ࠷ॳɺ ͱ<>͸ಉͩ͡ͱࢥ͍ͬͯͨ w εΧϥʔม਺ͳͷʹ഑ྻʂ w 1ZUIPOͰ͸഑ྻͱݴͬͨΒ͜Ε͚ͩ @a =

(0, 1, 2); \$ref = \@a; \$ref = [0, 1, 2]; a = [0, 1, 2]
17. ### ͳΜͰҾ਺Ϧετͳ͍ͷ w !@Λड͚ͱΔ͚Ͳ࢖͍ํࣗ༝͗͢ w 1ZUIPOͩͱؔ਺ͷσϑΥϧτ஋ΛઃఆͰ͖Δ͠  ΩʔϫʔυͰݺͿ͜ͱ΋ग़དྷΔʂ my (\$a, \$b) =

@_; my \$a = shift; my %args = @_;
18. ### ͪͳΈʹ w σϑΥϧτ஋Λ࢖ͬͨݺͼग़͠ w ී௨ͷݺͼग़͠ w Ωʔϫʔυݺͼग़͠ def hello(name =

'mihyaeru'): print 'Hello, %s' % name ! hello() hello('dareka') hello(name = 'anata')

20. ### ࠷ॳʹࢥͬͨෆຬ w มͳه߸ଟͯ͘ҙຯෆ໌ w ίϯςΩετʁʁʁ w ຖճNZͬͯॻ͘ͷ໘౗͍͘͞ w ਅِ஋Σʜʜ w

ϦϑΝϨϯεपΓ͕Θ͔Γʹ͍͘ w Ҿ਺Ϧετ͸Ͳ͜ʂʁ
21. ### ࠷ॳʹࢥͬͨෆຬࠓ͸ w มͳه߸ଟͯ͘ҙຯෆ໌ w ίϯςΩετʁʁʁ w ຖճNZͬͯॻ͘ͷ໘౗͍͘͞ w ਅِ஋Σʜʜ w

ϦϑΝϨϯεपΓ͕Θ͔Γʹ͍͘ w Ҿ਺Ϧετ͸Ͳ͜ʂʁ ׳ΕΕ͹ා͘ͳ͍ʂ ׳ΕΕ͹ʢ͈́ ॻ͍ͨํ͕҆৺ײ͋Δ ਅِ஋Σʜʜ Ҿ਺ʹ໊લ͸ͳ͘୯ͳΔϦετ ະͩʹͬ͘͠Γ͜ͳ͍

24. ### ແ໊ؔ਺͕࢖͍΍͍͢ w 1ZUIPOʹ΋MBNCEBͱ͍͏ແ໊ؔ਺Λ࡞Δه๏ΞϦ w ࣜΛ͔ͭ͠ೖΕΒΕͳ͍͔Β਺จͷॲཧ͸μϝ hoge_call(sub { # do #

something # hoge }); def temp(): # do # something # hoge ! hoge_call(temp) 1FSM 1ZUIPO
25. ### NBQͱ͔HSFQ͕ྑ͍ײ͡ Ҿ਺Λح਺͚ͩʹߜΓࠐΜͰɺɺɺ  ৐ͨ͠஋ͷ഑ྻʹ͢Δɺɺɺ  తͳॲཧ my @squared_odds = map { \$_

* \$_ } grep { \$_ % 2 == 1 } @_;

% 2 == 1]
27. ### 1ZUIPOͩͱ [x * x for x in nums if x

% 2 == 1] NBQʹ૬౰ HSFQʹ૬౰
28. ### Ϧετ಺แදه [x * x for x in X if x

% 2 == 1] {x2 | x ∈ X, x % 2 = 1} ਺ֶͷू߹ʹ͓͚Δ಺แతදه͕ݩʹͳ͍ͬͯΔ
29. ### ϝιουͷTFMG 1ZUIPOΛኲኵͱͤͯ͞਌ۙײ͋Γ sub method { my (\$self, \$hoge) = @_;

} def method(self, hoge): pass