Comma versus list

325 views

Published on

Lightning talk given at YAPC::EU 2012

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
325
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Comma versus list

    1. 1. ( ) versus ,Damien Krotkine ( dams )
    2. 2. Parens versus Comma
    3. 3. Parens versus Comma or, what people say...
    4. 4. Parens versus Comma or, what people say...or, a lame excuse to play with Keynote’s effects...
    5. 5. my @array = ( 1, 2, 3 )
    6. 6. my @array = ( 1, 2, 3 )
    7. 7. my @array = ( 1, 2, 3 )
    8. 8. my @array = ( 1, 2, 3 ) ( 1, 2, 3 )That’s a list, right ?
    9. 9. my @array = ( 1, 2, 3 ) ( 1, 2, 3 )That’s a list, right ?But what makes it a list ?
    10. 10. People say“ Oh that’s the parens”“ The parentheses make it a list”
    11. 11. People say“ Oh that’s the parens”“ The parentheses make it a list”People also say :“ See, if you remove the parentheses, it doesn’twork”
    12. 12. my @array = (1, 2, 3);say “@array” # returns 1 2 3 Yay !
    13. 13. my @array = 1, 2, 3 ;say “@array” # returns 1 Booh !
    14. 14. So people say“ So, it must be the parentheses”So now people say :“parentheses are the list operator in Perl 5”
    15. 15. I say :“Oh really ? ”
    16. 16. Let’s see... operators, what’s the list of Perloperators ?
    17. 17. Let’s see... operators, what’s the list of Perloperators ?man perlop
    18. 18. -> &++ -- | ^** &&! ~ + - || //=~ !~ .. ...* / % x ?:+ - . = += -= *= etc.<< >> , =>< > <= >= lt gt le ge not== != <=> eq ne cmp ~~ and xor
    19. 19. -> &++ -- | ^** &&! ~ + - || //=~ !~ .. ...* / % x ?:+ - . = += -= *= etc.<< >> , =>< > <= >= lt gt le ge not== != <=> eq ne cmp ~~ and xor There is no ( ) operator
    20. 20. -> &++ -- | ^** &&! ~ + - || //=~ !~ .. ...* / % x ?:+ - . = += -= *= etc.<< >> , =>< > <= >= lt gt le ge not== != <=> eq ne cmp ~~ and xor There is no ( ) operator
    21. 21. -> &++ -- | ^** &&! ~ + - || //=~ !~ .. ...* / % x ?:+ - . = += -= *= etc.<< >> , =>< > <= >= lt gt le ge not== != <=> eq ne cmp ~~ and xor There is no ( ) operator However there is a comma operator
    22. 22. -> &++ -- | ^** &&! ~ + - || //=~ !~ .. ...* / % x ?:+ - . = += -= *= etc.<< >> , =>< > <= >= lt gt le ge not== != <=> eq ne cmp ~~ and xor There is no ( ) operator However there is a comma operator , That’s the operator
    23. 23. The comma operator has a very lowprecedence, but it’s still an operatorParentheses ( ) are just there to modifyprecedence
    24. 24. ( 1, 2, 3 ) is a list
    25. 25. ( 1, 2, 3 ) is a list1, 2, 3 is also a list
    26. 26. my @list = 1, 2, 3
    27. 27. my @list = 1, 2, 3So why doesn’t this work ?
    28. 28. my @list = 1, 2, 3So why doesn’t this work ?That’s because = has greater precedencethan ,
    29. 29. my @array = 1, 2, 3;
    30. 30. my @array = 1, 2, 3;is really
    31. 31. my @array = 1, 2, 3;is really(my @array = 1), 2, 3;
    32. 32. my @array = 1, 2, 3;is really(my @array = 1), 2, 3;
    33. 33. And it’s also
    34. 34. And it’s also( (my @array = 1), 2, 3 );
    35. 35. And it’s also( (my @array = 1), 2, 3 );So it’s really a list ! We are just not lookingat it completely when looking at @array
    36. 36. Why is it useful to know ?
    37. 37. It makes you realize you don’t need ( ) inmany situations
    38. 38. return 1, 2, 3;
    39. 39. return 1, 2, 3;do_stuff or log(“error”), die;
    40. 40. return 1, 2, 3;do_stuff or log(“error”), die;my $self = bless { }, $class;
    41. 41. return 1, 2, 3;do_stuff or log(“error”), die;my $self = bless { }, $class;etc.
    42. 42. return 1, 2, 3;do_stuff or log(“error”), die;my $self = bless { }, $class;etc.btw this doesn’t work
    43. 43. return 1, 2, 3;do_stuff or log(“error”), die;my $self = bless { }, $class;etc.btw this doesn’t workdo_stuff || log(“error”), die;
    44. 44. return 1, 2, 3;do_stuff or log(“error”), die;my $self = bless { }, $class;etc.btw this doesn’t workdo_stuff || log(“error”), die;=> go learn your operators’ precedence
    45. 45. So please don’t say that ( ) is the Perl 5 listoperator: it is notGive more love to the comma operator,it’s often forgotten
    46. 46. So please don’t say that ( ) is the Perl 5 listoperator: it is notGive more love to the comma operator,it’s often forgotten ♥
    47. 47. So please don’t say that ( ) is the Perl 5 listoperator: it is notGive more love to the comma operator,it’s often forgotten ♥And don’t listen to what people say...
    48. 48. Thanks Damien Krotkine ( dams )

    ×