Blame


1 ffd9a51f 2023-08-04 jrmu #!/usr/bin/perl
2 ffd9a51f 2023-08-04 jrmu
3 ffd9a51f 2023-08-04 jrmu # Using the pattern test program, make a pattern to match the string 'match'.
4 ffd9a51f 2023-08-04 jrmu # Try the program with the input string 'beforematchafter'. Does the output
5 ffd9a51f 2023-08-04 jrmu # show the three parts of the match in the right order?
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 (/match/) {
14 ffd9a51f 2023-08-04 jrmu print "Matched: |$`<$&>$'|\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 }