Skip to content

Instantly share code, notes, and snippets.

@kirklewis
Created October 1, 2018 22:30
Show Gist options
  • Save kirklewis/f2b9987cb330e7b702d1e8ed46f86a22 to your computer and use it in GitHub Desktop.
Save kirklewis/f2b9987cb330e7b702d1e8ed46f86a22 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use v5.20.3;
use strict;
use warnings;
# Basic String Interpolation with Scalars and Lists
my $PI = 3.14;
my @nums = (3, 2, 1);
say "scalar: $PI - list: @nums";
say "scalar: ${ PI } - list: @{ nums }";
say q();
# String Interpolation with Constants
use constant DEV_OPS => 'dev_ops';
my $status = 'online';
say "Team ${ \DEV_OPS } is ${ status }";
# or if we use more than one constant
say "Team ${ \DEV_OPS } - ${ \DEV_OPS } is ${ status }";
say q();
# Using Constants with Regular Expressions
use constant BLUE => 'blue';
use constant GREEN => 'green';
use constant RED => 'red';
use constant COLORS_REGEXP => qr/^(
${\BLUE} |
${\GREEN} |
${\RED}
)$/x;
my @colors = qw(blue yellow orange red);
say $_ =~ COLORS_REGEXP
? "$_ is valid"
: "$_ is invalid" foreach @colors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment