SlideShare une entreprise Scribd logo
1  sur  23
The WTFish side  of using Perl Lech Baczyński http://perl.baczynski.com
Thanks, Hurra I would like to thank Hurra Communications, the company that sponsored my trip here, probably the most Perl-ish company in Poland www.hurra.com
What do I mean by WTF Strange unexpected results of Perl code: ,[object Object]
Perl's strange behaviour (both seem to be the same after a while :-) ) Examples: foreach variable localization, “zero but true”, dangers of omitting brackets, lazy  print ... Some are for beginners (not-beginners – have patience!), some may puzzle intermediate programmers.
Lazy print Let's say you would like to see progress of a long computing... foreach my $element (@array) { # ..... long time operations ... $i++; if ( $i % 100 == 0) {  print ".";  }; Will it print dot every 100th iteration?  No. It will print all of them at once at the end.
Lazy print - continued $|++ WTF is $|++ ? It is incrementing one of Perl's strange variables (magic punctuation variables). $| If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel.  Using $|++ is not perl best practice. Solution:  use English; # '-no_match_vars'; then use the $OUTPUT_AUTOFLUSH  variable
Who needs brackets Omitting brackets – both convenient and dangerous $a="Hello"; $b="world"; print $a . " " . $b . ""; print "Found ". scalar @arr ." elements";
Who needs brackets - continued $a = 'Hello'; print ( length ( $a ) ); print length $a; output: 5 - ok print length $a . " letters" ; output: 14 – WTF?? Length was calculated of concatenated strings $a and "letters", thus length returned 14.  So beware - sometimes you may ignore brackets, sometimes you may not.
Regexps: {n,m} Let's say you want to match three to five small letters : /[a-z]{3,5}/ And now any number not less than three /[a-z]{3,}/ And now, analogically, any number not more than five /[a-z]{,5}/   # WRONG It works only one way - {n,}, not {,n} - the explanation is easy: you can easily write 0, but it not so easy to write infinity
Regexps: Minus (-) sign in character classes [ ] Beware of matching "-" in regexps. If you want to match letters a,b,c and minus sign: Good:  [-abc] Good:  [abc-] Bad: [a-bc] Good: [abc]
Regexps: delimiters Only if you use // then m is optional.  Some need to be closed other way than opened. /abc/  - ok |abc|  - wrong m|abc|  - will work m/abc/  - will work, m is optional m#abc#  - will work, not a comment m(abc) m{abc} m[abc]  - ok Perl Bast Practices: Don't use any delimiters other than // or m{}
Foreach  var localization  my @array = (1,2,3); my $var = 'foo'; foreach $var (@array) {  # note - no "my $var"  print $var . ""; } print 'Value after the loop: ' . $var . ""; Value of $var after loop is “foo”. It is the same as before loop! WTF?
Foreach  var localization - continued The same example but with $_  $_ = 'foo'; print; foreach (@array) { print; } print; And again, the $_ is the same as before loop! This behavior can be observed in "foreach" loops, but not in "while" loops. So be careful.
So, you would like to create two dimensional array? @array = ( (1,2,3), (4,5,6), (7,8,9)); Wrong. It makes @aray = (1,2,3,4,5,6,7,8,9);.  This is caled array flattening.  @array = ( [1,2,3], [4,5,6], [7,8,9]); You do not get exactly array of arrays - you get the array of references to array.
Autodefining var my $var;   # $var is not defined if (defined $var) { warn "yes"; } else {  warn "no"; } # warns: "no" if (defined $var->{'foo'}) {  warn "yes"; } else { warn "no"; } # well, it is not defined. But  "if (defined $var->{'foo'})" made our $var defined! if (defined $var) {  warn "yes"; } else { warn "no"; }  # warns: "yes"! print ref $var;   # HASH! Analogically, if ($var->[0]) makes an empty arrayref.
Fun with counting months, years and weekdays ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); Month day: from  1  to  31 Month:  0  to  11.  WTF? Explanation: This makes it easy to get a month name from a list: my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );  print "$abbr[$mon] $mday";
Fun with counting months, years and weekdays $year  is the number of years since 1900, not just the last two digits of the year. That is,  $year  is 123 in year 2023. We have seen using last two digits for year, and Y2K problems it made. We have seen counting time from 1970. We have seen counting time from begining of A.D. (like: 2009). So why 1900? It is strange, but it is the same in C and Java. Perl inherited it from C libs. It neither have the possiblility to store year in two digits, nor the possiblility not force  programmers to count year in special way. $year += 1900;
Fun with counting months, years and weekdays $wday is the day of the week, with 0 indicating Sunday and 3 indicating Wednesday. Monday is 1st, Saturday is 5th, Sunday is zeroth. Beware that Sunday is not 7th, nor 1st, as most people would thought. This solution is good for both groups of people - those that think that Monday is first day of weeks (as it is 1st) and those that Sunday is at the beginning of the week (as it is zeroth) ;-) Just be aware of those little traps in localtime.
Three ways of calling subroutine sub my_subroutine {... ,[object Object]
my_subroutine();  No need to declare earlier
&my_subroutine;  No need to declare earlier, too, but it passes the content of @_ to called subroutine! If you call subroutine with the "&" at beginning, you get an implicit argument list passed that you probably did not intend.
last  in function Imagine you have a loop and call a function (sub) in it – your, or from some module. And someone by mistake left there  last . It terminates your loop. for … { something…; function(); something… that would not be executed… }; For some people it is a WTF, for some it is very logical way, that it should work like.
The truth is out there What is false? ,[object Object]

Contenu connexe

Similaire à WTFin Perl

Beginning Perl
Beginning PerlBeginning Perl
Beginning PerlDave Cross
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlDave Cross
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XSbyterock
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fuclimatewarrior
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de JavascriptBernard Loire
 
Why Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, MarakanaWhy Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, MarakanaMarko Gargenta
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...Viktor Turskyi
 
Php Loop
Php LoopPhp Loop
Php Looplotlot
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 

Similaire à WTFin Perl (20)

Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XS
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Javascript
JavascriptJavascript
Javascript
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Why Scala?
Why Scala?Why Scala?
Why Scala?
 
Why Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, MarakanaWhy Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, Marakana
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...
 
Php Loop
Php LoopPhp Loop
Php Loop
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 

Dernier

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Dernier (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

WTFin Perl

  • 1. The WTFish side of using Perl Lech Baczyński http://perl.baczynski.com
  • 2. Thanks, Hurra I would like to thank Hurra Communications, the company that sponsored my trip here, probably the most Perl-ish company in Poland www.hurra.com
  • 3.
  • 4. Perl's strange behaviour (both seem to be the same after a while :-) ) Examples: foreach variable localization, “zero but true”, dangers of omitting brackets, lazy print ... Some are for beginners (not-beginners – have patience!), some may puzzle intermediate programmers.
  • 5. Lazy print Let's say you would like to see progress of a long computing... foreach my $element (@array) { # ..... long time operations ... $i++; if ( $i % 100 == 0) { print "."; }; Will it print dot every 100th iteration? No. It will print all of them at once at the end.
  • 6. Lazy print - continued $|++ WTF is $|++ ? It is incrementing one of Perl's strange variables (magic punctuation variables). $| If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Using $|++ is not perl best practice. Solution: use English; # '-no_match_vars'; then use the $OUTPUT_AUTOFLUSH variable
  • 7. Who needs brackets Omitting brackets – both convenient and dangerous $a="Hello"; $b="world"; print $a . " " . $b . ""; print "Found ". scalar @arr ." elements";
  • 8. Who needs brackets - continued $a = 'Hello'; print ( length ( $a ) ); print length $a; output: 5 - ok print length $a . " letters" ; output: 14 – WTF?? Length was calculated of concatenated strings $a and "letters", thus length returned 14. So beware - sometimes you may ignore brackets, sometimes you may not.
  • 9. Regexps: {n,m} Let's say you want to match three to five small letters : /[a-z]{3,5}/ And now any number not less than three /[a-z]{3,}/ And now, analogically, any number not more than five /[a-z]{,5}/ # WRONG It works only one way - {n,}, not {,n} - the explanation is easy: you can easily write 0, but it not so easy to write infinity
  • 10. Regexps: Minus (-) sign in character classes [ ] Beware of matching "-" in regexps. If you want to match letters a,b,c and minus sign: Good: [-abc] Good: [abc-] Bad: [a-bc] Good: [abc]
  • 11. Regexps: delimiters Only if you use // then m is optional. Some need to be closed other way than opened. /abc/ - ok |abc| - wrong m|abc| - will work m/abc/ - will work, m is optional m#abc# - will work, not a comment m(abc) m{abc} m[abc] - ok Perl Bast Practices: Don't use any delimiters other than // or m{}
  • 12. Foreach var localization my @array = (1,2,3); my $var = 'foo'; foreach $var (@array) { # note - no "my $var" print $var . ""; } print 'Value after the loop: ' . $var . ""; Value of $var after loop is “foo”. It is the same as before loop! WTF?
  • 13. Foreach var localization - continued The same example but with $_ $_ = 'foo'; print; foreach (@array) { print; } print; And again, the $_ is the same as before loop! This behavior can be observed in "foreach" loops, but not in "while" loops. So be careful.
  • 14. So, you would like to create two dimensional array? @array = ( (1,2,3), (4,5,6), (7,8,9)); Wrong. It makes @aray = (1,2,3,4,5,6,7,8,9);. This is caled array flattening. @array = ( [1,2,3], [4,5,6], [7,8,9]); You do not get exactly array of arrays - you get the array of references to array.
  • 15. Autodefining var my $var; # $var is not defined if (defined $var) { warn "yes"; } else { warn "no"; } # warns: "no" if (defined $var->{'foo'}) { warn "yes"; } else { warn "no"; } # well, it is not defined. But "if (defined $var->{'foo'})" made our $var defined! if (defined $var) { warn "yes"; } else { warn "no"; } # warns: "yes"! print ref $var; # HASH! Analogically, if ($var->[0]) makes an empty arrayref.
  • 16. Fun with counting months, years and weekdays ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); Month day: from 1 to 31 Month: 0 to 11. WTF? Explanation: This makes it easy to get a month name from a list: my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); print "$abbr[$mon] $mday";
  • 17. Fun with counting months, years and weekdays $year is the number of years since 1900, not just the last two digits of the year. That is, $year is 123 in year 2023. We have seen using last two digits for year, and Y2K problems it made. We have seen counting time from 1970. We have seen counting time from begining of A.D. (like: 2009). So why 1900? It is strange, but it is the same in C and Java. Perl inherited it from C libs. It neither have the possiblility to store year in two digits, nor the possiblility not force programmers to count year in special way. $year += 1900;
  • 18. Fun with counting months, years and weekdays $wday is the day of the week, with 0 indicating Sunday and 3 indicating Wednesday. Monday is 1st, Saturday is 5th, Sunday is zeroth. Beware that Sunday is not 7th, nor 1st, as most people would thought. This solution is good for both groups of people - those that think that Monday is first day of weeks (as it is 1st) and those that Sunday is at the beginning of the week (as it is zeroth) ;-) Just be aware of those little traps in localtime.
  • 19.
  • 20. my_subroutine(); No need to declare earlier
  • 21. &my_subroutine; No need to declare earlier, too, but it passes the content of @_ to called subroutine! If you call subroutine with the "&" at beginning, you get an implicit argument list passed that you probably did not intend.
  • 22. last in function Imagine you have a loop and call a function (sub) in it – your, or from some module. And someone by mistake left there last . It terminates your loop. for … { something…; function(); something… that would not be executed… }; For some people it is a WTF, for some it is very logical way, that it should work like.
  • 23.
  • 26. undef
  • 27. () empty list what about "0.0"? And "0E0"? "0.0", "0E0", "0 but true","false","foo" are all true. 0.0 is false (number, not string)
  • 28. The truth is out there “0 but true” - self documenting WTF :) It is true, but when treated as a number it is zero. print "0 but true" ? "true" : "false"; print "0 but true" + 0 ? "true" : "false"; First is true, second is false. You can add it to number: print "0 but true" + 7; As most other strings: print "foo" + 7; Beware of strings starting with inf... nad nan...
  • 29. Comparing apples to oranges if ("apple" == "orange") { .... True! Beware of "==" and "eq" difference. "==" is for numbers, "eq" for strings. perl 5.10 and later: $scalar ~~ $scalar; If both look like numbers, do "==", otherwise do "eq"
  • 30. That's all folks! Thank you.