Files
basic-computer-games/31_Depth_Charge/perl
Martin Thoma e64fb6795c MAINT: Apply pre-commit
Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
2022-03-05 09:29:23 +01:00
..
2022-03-05 09:29:23 +01:00

Original source downloaded from Vintage Basic

Conversion to Perl

Conversion

Not a difficult conversion - but a chance to throw in a few ways Perl makes life easy.

  • To get the sub permission which is a random location in the g x g x g grid we can use:

    • assigning multiple variables in list form ($a,$b,$c) = (?,?,?)
    • where the list on the right hand side is generated with a map function
  • We use ternarys to generate the message if you miss the sub.

    • We use join to stitch the pieces of the string together.
    • If we have a ternary where we don't want to return anything we return an empty list rather than an empty string - if you return the latter you still get the padding spaces.