Perl 6 in a hands-on test
Game Mode
Keyboard input from the command line usually requires the user to confirm each entry with the return key, but in game mode, you want the blackjack script to respond directly to key presses. The raw terminal mode is used for this on Unix systems; you will only want to enable this during the actual entry and reset to normal cooked mode immediately after; otherwise, the terminal no longer responds to shell commands typed after the program has exited.
This is why the prompt-char()
function defined in line 56 (Perl 6 allows dashes in function names) uses the stty
utility to run a shell command that enables raw mode and disables it again on leaving the routine. Perl 6 provides the keywords ENTER
and LEAVE
to perform actions when entering and exiting a function. From the $TTY
file handle in the previously opened terminal, read(1)
consumes a byte via the prompt-char()
function, and the downstream decode()
method converts the buffer byte to an ASCII character that the script can later compare with a letter such as "h" (hit) or "s" (stand).
Perl 6 has a switch statement, which goes by the name of given/when and is used in line 31 to compare the player's keyboard input with specified letters and initiate the corresponding game controls.
Perl 6 vs. Perl 5
The game flow in Listing 4 is pretty self-explanatory, and if you compare the lines of code required for the implementation, Perl 6 comes off slightly ahead. Also the dropped parentheses in the for
and while
loop heads have a positive effect on readability.
Will Perl 6 assert itself? It is probably too early to tell; production tests will decide the outcome. Larry Wall hinted that he was working on a Perl 6 book at the conference in Orlando but left open how long it will take to publish it. If you want to draw lessons from the past, then you might guess that a good chunk of time may pass between announcement and release in Larry's private empire.
Mike Schilli
Mike Schilli works as a software engineer in the San Francisco Bay Area. He can be contacted at mailto:mschilli@perlmeister.com. Mike's homepage can be found at http://perlmeister.com.
Infos
- Schrodinger's cat: https://en.wikipedia.org/wiki/Schrodinger%27s_cat
- "Quantum Casino" by Michael Schilli, Linux Magazine, January, 2004, pg. 61: http://perlmeister.com/lme/prod-0401.pdf
- Listings for this article: ftp://ftp.linux-magazine.com/pub/listings/magazine/191/Perl
- Blackjack soft 17 rule: http://www.readybetgo.com/blackjack/strategy/soft-17-rule-2496.html
« Previous 1 2 3 4 5
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.