Last active
January 9, 2022 17:41
-
-
Save samiam2013/0d66a075b3119a8441aea30e8467c8d9 to your computer and use it in GitHub Desktop.
use diagnostics; # they're very very good
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use diagnostics; | |
=pod | |
██╗░░░██╗░██████╗███████╗ | |
██║░░░██║██╔════╝██╔════╝ | |
██║░░░██║╚█████╗░█████╗░░ | |
██║░░░██║░╚═══██╗██╔══╝░░ | |
╚██████╔╝██████╔╝███████╗ | |
░╚═════╝░╚═════╝░╚══════╝ | |
██████╗░██╗░█████╗░░██████╗░███╗░░██╗░█████╗░░██████╗████████╗██╗░█████╗░░██████╗██╗ | |
██╔══██╗██║██╔══██╗██╔════╝░████╗░██║██╔══██╗██╔════╝╚══██╔══╝██║██╔══██╗██╔════╝╚═╝ | |
██║░░██║██║███████║██║░░██╗░██╔██╗██║██║░░██║╚█████╗░░░░██║░░░██║██║░░╚═╝╚█████╗░░░░ | |
██║░░██║██║██╔══██║██║░░╚██╗██║╚████║██║░░██║░╚═══██╗░░░██║░░░██║██║░░██╗░╚═══██╗██╗ | |
██████╔╝██║██║░░██║╚██████╔╝██║░╚███║╚█████╔╝██████╔╝░░░██║░░░██║╚█████╔╝██████╔╝╚█║ | |
╚═════╝░╚═╝╚═╝░░╚═╝░╚═════╝░╚═╝░░╚══╝░╚════╝░╚═════╝░░░░╚═╝░░░╚═╝░╚════╝░╚═════╝░░╚╝ | |
This gist is all about the `use` statemtents above | |
I worked in perl for more than a year without knowing | |
perl had this kind of descriptive error output | |
I had a hunch one day after I had seen this error; | |
specifically that using a stricter standard would | |
have had to point out an incorrect assignment. | |
The company I worked for at the time _only_ required | |
`use strict;` and I had seen use of `use warnings;` | |
only in standalone code because the amount of | |
errors that would spill out of internally | |
developed libraries was insane. | |
I turned on `use diagnostics` for the first time | |
and when you run this code with that strict of a | |
standard, Perl stops you and explains with an essay | |
longer than this one why what you did is technically | |
incoherent. | |
use this code by typing | |
perl ./perl_assignment_error.pl; | |
in any linux distribution after downloading or copying | |
this file | |
=cut | |
#----------------------------------------------------- | |
# The actual code | |
#----------------------------------------------------- | |
my $string = "Hello World"; | |
# regex matching the first letters with groups, | |
# so $1 should be 'Hello' | |
# $2 should be 'World' | |
$string =~ /(H.*)\s(W.*)/; | |
# this is where it hits the error in #use warnings or #use diagnostics | |
my ($h, $w) = $1, $2; | |
# the correct use of this functionality I wanted is | |
# my ($h, $w) = ($1, $2); # parentheses are very important | |
# prints out 'h: Hello, w: ' and a newline because of the assignment error | |
print STDOUT "h: $h, w: $w\n"; | |
exit; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment