Blob


1 #!/usr/bin/perl
3 # Extra credit exercise: modify the program from the previous exercise so
4 # that immediately following the word ending in 'a' it will also capture
5 # up-to-five characters (if there are that many characters, of course) in a
6 # separate capture variable. Update the code to display both capture
7 # variables. For example, if the input string says 'I saw Wilma yesterday',
8 # the up-to-five characters are " yest" (with the leading space). If the
9 # input is "I, Wilma!", the extra capture should have just one character.
10 # Does your pattern still match just plain 'wilma'?
12 use warnings;
13 use strict;
14 use utf8;
16 while (<>) {
17 chomp();
18 if (/\b(?<word>\w*a)\b(?<trail>.{0,5})/) {
19 print "Matched: $`<$&>$': word contains '$+{word}', trailed by '$+{trail}'\n";
20 } else {
21 print "No match: |$_|\n";
22 }
23 }