aboutsummaryrefslogtreecommitdiff
path: root/challenge-099/arne-sommer/perl/pattern-match-perl
blob: 632204f90c581be593da2e80bb0ad632e05a0ec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /usr/bin/env perl

use strict;
use warnings;
use feature 'say';

use Getopt::Long;

my $verbose = 0;

GetOptions("verbose" => \$verbose);

my $S = shift(@ARGV);
my $P = shift(@ARGV);

die '"$S" must have length' unless length $S;
die '"$P" must have length' unless length $P;

$P =~ s/\*/.*/g;
$P =~ s/\?/./g;

say ": Perl Regex: $P " if $verbose;

say $S =~ /^$P$/ ? 1 : 0;