#!/usr/bin/env perl # If you've mapped a network drive, use this line: chdir "/Volumes/Corpora/en/brown/"; # If you've logged in to jones, comment out the previous line and # uncomment this line: #chdir "/Volumes/Data/Corpora/en/brown/"; @all_files = <*>; # Q: what do we need to do to keep track of the number of occurrences # of a particular search? $counter = 0; # loop over all files in the directory foreach (@all_files) { # get appropriate files from directory if (/\d/) { # open each file, one at a time $file_name = $_; open FILE, '<', $file_name; # read each line in the file while () { # remove trailing newline chomp; # case #1: help/verb + following verb while (m{\b( help\w*?/v\w*? # help \s+ # (space) \w+/v\w*? # following verb )\b}gix) { # 'x' option allows us to be RE on # separate lines print "$file_name: $1\n"; $counter++; } # case #2: help/verb + to + following verb # while (m{\b( # help\w*?/v\w*? # help # \s+ # (space) # to/to # to # \s+ # (space) # \w+/v\w*? # following verb # )\b}gix) { # print "$file_name: $1\n"; # } # case #3: help/verb + NP + following verb # while (m{\b( # help\w*?/v\w*? # help # \s+ # (space) # \w+/[np]\w*? # tag starts with 'n' or 'p' # \s+ # (space) # \w+/v\w*? # following verb # )\b}gix) { # print "$file_name: $1\n"; # } # case #4: help/verb + NP + to + following verb # while (m{\b( # help\w*?/v\w*? # help # \s+ # (space) # \w+/[np]\w*? # tag starts with 'n' or 'p' # \s+ # (space) # to/to # to # \s+ # (space) # \w+/v\w*? # following verb # )\b}gix) { # print "$file_name: $1\n"; # } } } } print "Number of occurrences = $counter\n";