Blame


1 ffd9a51f 2023-08-04 jrmu #!/usr/bin/perl
2 ffd9a51f 2023-08-04 jrmu
3 ffd9a51f 2023-08-04 jrmu # Modify the program from the previous exercise so that the word ending with
4 ffd9a51f 2023-08-04 jrmu # the letter 'a' is captured into $1. Update the code to display that
5 ffd9a51f 2023-08-04 jrmu # variable's contents in single quotes, something like $1 contains 'Wilma'.
6 ffd9a51f 2023-08-04 jrmu
7 ffd9a51f 2023-08-04 jrmu use warnings;
8 ffd9a51f 2023-08-04 jrmu use strict;
9 ffd9a51f 2023-08-04 jrmu use utf8;
10 ffd9a51f 2023-08-04 jrmu
11 ffd9a51f 2023-08-04 jrmu while (<>) {
12 ffd9a51f 2023-08-04 jrmu chomp();
13 ffd9a51f 2023-08-04 jrmu if (/\b(\w*a)\b/) {
14 ffd9a51f 2023-08-04 jrmu print "Matched: $`<$&>$': \$1 contains '$1'\n";
15 ffd9a51f 2023-08-04 jrmu } else {
16 ffd9a51f 2023-08-04 jrmu print "No match: |$_|\n";
17 ffd9a51f 2023-08-04 jrmu }
18 ffd9a51f 2023-08-04 jrmu }