#!/usr/bin/perl -w ############### # # patternMatch # # Interactively ask the user for a perl regular expression, # then prompt for various strings to try that pattern against. # # Based on R. Schwartz's pattern_test from Learning Perl, v3. # - Jim Mahoney, Oct 2001 # ########### use strict; print " -- patternMatch -- \n"; print " Enter the regexp : "; chomp(my $regexp = ); while (1) { print " Enter a string to match against : "; chomp(my $text = ); print(" Done.\n") , exit unless $text; if ( $text =~ /$regexp/) { print " Matched: |$`<$&>$'|\n"; print " and memory one got <$1>\n" if $1; print " and memory two got <$2>\n" if $2; } else { print " No match.\n"; } }