Advertisement
chotoipho

ch8_ex4.pl

Dec 18th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.37 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. my $pattern = '(?<word>\b\w*a\b)';
  5. print "\$pattern = $pattern\n\n";
  6. print "Type a string to see if it matches.\n";
  7.  
  8. while (<STDIN>) {
  9.   chomp;
  10.   if ($_ =~ m/$pattern/) {
  11.     printf "%-40s %s\n", "Matched: |$`<$&>$'|", "\$+{word} contains $+{word}";
  12.     }
  13.   else {
  14.     printf "%-50s\n", "No match: |$_|";
  15.   }
  16.  
  17. }
  18. print "done.\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement