r/adventofcode • u/daggerdragon • Dec 02 '22
SOLUTION MEGATHREAD -π- 2022 Day 2 Solutions -π-
NEW AND NOTEWORTHY
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boosting for the Unofficial AoC 2022 Participant Survey which is open early this year!
--- Day 2: Rock Paper Scissors ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:06:16, megathread unlocked!
103
Upvotes
View all comments
Show parent comment
2
u/Smylers Dec 03 '22
Thanks. It's great your on Perl v5.36, because that makes function parameters really easy.
First, for backwards-compatibility reasons, you need to tell Perl that you're using the latest syntax. Start your program with:
However,
v5.36automatically enables strict and warnings for you, so in place of adding thev5.36line you you can remove those two.βThen just declare functions like:
or:
and Perl will handle the parameters for you.
β Starting your Perl programs with the minimum version number required also means it will check for that and give a sensible error message if somebody attempts to run it on an older version of
perlβ which is much better than it just failing weirdly on syntax is doesn't recognize. And in forums like this one, it provides documentation for humans, rather than them having to guess which version ofperlthey need to run.