Created
October 1, 2018 22:30
-
-
Save kirklewis/f2b9987cb330e7b702d1e8ed46f86a22 to your computer and use it in GitHub Desktop.
This file contains 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/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