Computer Sciences Department logo

CS 368-1 (2011 Summer) — Day 4 Code Sample

The code from class is copied below.

Line-Numbering Code

#!/usr/bin/perl

use strict;
use warnings;

open(INPUT, 'input.txt') or
    die "Could not open 'input.txt': $!\n";

open(OUTPUT, '>', 'output.txt') or
    die "Could not open 'output.txt': $!\n";

my $number = 1;
while (my $line = <INPUT>) {
    print OUTPUT "$number: $line";
    $number++;
}

close(INPUT);
close(OUTPUT);