Blame


1 ffd9a51f 2023-08-04 jrmu #!/usr/bin/perl
2 ffd9a51f 2023-08-04 jrmu ## Copyright (C) 2023 by jrmu <jrmu@ircnow.org>
3 ffd9a51f 2023-08-04 jrmu ##
4 ffd9a51f 2023-08-04 jrmu ## Permission is granted to use, copy, modify, and/or distribute
5 ffd9a51f 2023-08-04 jrmu ## this work for any purpose with or without fee. This work is
6 ffd9a51f 2023-08-04 jrmu ## offered as-is, with absolutely no warranty whatsoever. The
7 ffd9a51f 2023-08-04 jrmu ## author is not responsible for any damages that result from
8 ffd9a51f 2023-08-04 jrmu ## using this work.
9 ffd9a51f 2023-08-04 jrmu
10 ffd9a51f 2023-08-04 jrmu # Make a pattern that will match three consecutive copies of whatever is
11 ffd9a51f 2023-08-04 jrmu # currently contained in $what. That is, if $what is fred, your pattern
12 ffd9a51f 2023-08-04 jrmu # should match fredfredfred. If $what is fred|barney, your pattern should
13 ffd9a51f 2023-08-04 jrmu # match fredfredbarney or barneyfredfred or barneybarneybarney or many other
14 ffd9a51f 2023-08-04 jrmu # variations. (Hint: you should set $what at the top of the pattern test
15 ffd9a51f 2023-08-04 jrmu # program with a statement like my $what = 'fred|barney';.)
16 ffd9a51f 2023-08-04 jrmu
17 ffd9a51f 2023-08-04 jrmu use warnings;
18 ffd9a51f 2023-08-04 jrmu use strict;
19 ffd9a51f 2023-08-04 jrmu use utf8;
20 ffd9a51f 2023-08-04 jrmu
21 ffd9a51f 2023-08-04 jrmu my $what = "fred|barney";
22 ffd9a51f 2023-08-04 jrmu
23 ffd9a51f 2023-08-04 jrmu while (<>) {
24 ffd9a51f 2023-08-04 jrmu chomp;
25 ffd9a51f 2023-08-04 jrmu if (/($what){3}/) {
26 ffd9a51f 2023-08-04 jrmu print ("Match: $_\n");
27 ffd9a51f 2023-08-04 jrmu } else {
28 ffd9a51f 2023-08-04 jrmu print ("Not matched: $_\n");
29 ffd9a51f 2023-08-04 jrmu }
30 ffd9a51f 2023-08-04 jrmu }