SlideShare una empresa de Scribd logo
1 de 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]

Más contenido relacionado

Similar a 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
 

Similar a 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
 

Último

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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Último (20)

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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

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.