>>what anyone thinks would be the best way of implementing this program in PERL?
Get used to thinking in hashes :-)
Code:
#!/usr/bin/perl -w
use strict;
my %frequency;
while (<>) {
s/\W+\s|\W+$/ /g; # Removed extraneous punctuation
my @words = split /\s+/, $_; # Break up the words
# Increment the frequencies for each word
for (@words) {
$frequency{$_}++;
}
}
# Print :-)
for (sort keys %frequency) {
print $_, "\t-- ", $frequency{$_}, "\n";
}
Run this by saying
Code:
% script.pl wordfile.txt
>>I was wondering if anyone could tell me if binary trees and linked lists can be created in PERL
Yes, here's a quick and easy linked list that you'll probably never need since Perl arrays are so flexible :-)
Code:
#!usr/bin/perl -w
$head = undef;
for (1..5) {
$head = [$_, $head];
}
for (; defined $head; $head = $head->[1]) {
print $head->[0];
}
Binary trees really aren't any harder, isn't Perl nice? :-)