For all of these solutions, you should realize there are often many ways to
solve a problem, and my solution is only one of those ways. Your solution is
just as good, as long as it also produces the right answer.
- exp.pl
- reverse.pl
- Remember that good form in type-checking requires you to put a caret (^)
at the beginning of the regular expression and a dollar sign ($) at the
end of the regular expression so that your program can be sure that there
is not extra junk in the data.
- /^[mf]$/
- /^\d{5}$/
- /^(\d{1,2}-\d{1,2}-(19|20)\d{2})$/
- /^(\d{10}|\d{3}-\d{3}-\d{4}|\(\d{3}\) ?\d{3}-\d{4})$/
- /^\w+@\w+(.\w+)*$/
- credit-card.pl
- long.pl
-
- neg.pl: Reads the input as a stream
of pixels, negates each one by subtracting it from 255, and prints
it out. The first four "pixels" are actually header information that
I just echo out.
- hflip.pl: Reads the input as a
stream of pixels. The first four "pixels" are actually header
information that I just echo out. I then unshift a column's worth
of pixels into an array and print the array using the join command.
Unshifting is like pushing the items onto a stack, which reverses
them.
I repeat this procedure for each row.
- vflip.pl: To show you that there
are many ways to solve the same problem in Perl, I have included
Kristy Van Horweder's solution. It is line-oriented solution that
reads the input a line at a time. It
uses the specific format of the first three lines of the pgm file
to extract the header information and print it out. It then reads
the remaining lines into a huge array and indexes into the array
in order to extract the last row, then the next to last row, etc.
- word_count.pl: My solution puts
the command line arguments into a hash table and initializes their
word counts to 0. For each word in the file we check whether or not the
word is in the hash table, and if so, increment that word's count. I
have to do some manipulation to clean up the words, including using the
lc function to lowercase the words and a regular expression to
extract the leading, alphanumeric portion of a word.