Computer Sciences Department logo

CS 368-1 (2011 Summer) — Day 8 Script

This is the matching script from the class today. It takes a single argument on the command line, which is a file. The script will read the file, line by line, and print only the lines that match the given regular expression.

use strict;
use warnings;

open(INPUT, '<', $ARGV[0])
    or die "Could not open file: $!\n";

while (<INPUT>) {
    print if /cat/;

close INPUT;