# File: search1.pl # Title: Input from keyboard a string and a REGular EXpression (pattern) # Check if the word has the pattern: $s =~ /$p/g # Author: Mihaela Malita # Input string? abcde # Input pattern? bc # Pattern found! S not modified: abcde # PATTERN. Variable $& is: bc # BEFORE.Variable $` is: a AFTER.Variable $\' is: de # Position of pattern bc in abcde is: 3 # Continue(y/n)?= n # Bye $yesorno = 'y'; while ($yesorno eq "y") { print "Input string? "; $s = ; chop($s); print "Input pattern? "; $p = ; chop($p); if ( $s =~ /$p/g ) # use the operator =~ look for the pattern Global (g) {print "Pattern found! S not modified:", $s; print "\n"; print 'PATTERN. Variable $& is: '; print "$&"; print "\n"; print 'BEFORE.Variable $` is: '; print "$`"; print ' AFTER.Variable $\' is: '; print "$'"; print "\nPosition of pattern $& in $s is: ", pos($s); } else {print "Pattern NOT found!";} print("\nContinue(y/n)?= "); $yesorno = ; chop($yesorno); } print "Bye"; exit;