#! /usr/bin/perl

# concordance, find list of line numbers where each word appears

while(<>) {                              # iterate over lines in named file
    $iline++;                            # increment line number 
    tr/A-Za-z/ /cs;                      # remove punctuation
    foreach $word (split(' ', lc $_)) {  # each word in line, lc is lowercase
	my $wref = $loc{$word};
	my @wloc = @$wref;
	push(@wloc, $iline);
	$loc{$word} = \@wloc;
    }
}

foreach $word (sort keys %loc) {         # sort words found
    my $wref = $loc{$word};
    my @wloc = @$wref;
    print "$word @wloc\n";               # print word with its occurences
}



