[Omaha.pm] [olug] Bash TCP scripting

George Neill georgen at neillnet.com
Tue Jan 1 13:49:31 PST 2008


Jay,

> while (<>) {
>     foreach (/([a-zA-Z0-9'-]+)/g) {
>        $cnt{lc($_)}++;
>     }
> }
>
> foreach (sort keys %cnt) {
>     print "$_ $cnt{$_}\n";
> }

You could come pretty close to the amount of code written here if you
were using C++ STL  (std::map and algorithms)  Your PERLy
implementation is -not- the same though ... you are using a hash! not
a linked list.  :)

> 2 weeks later I turned in my 400 lines of C++ (which I can't share or
> the nuns will whack my knuckles with a ruler).

Of course.

> As I mentioned, the C++ solution was a lot more code then just
> solving the problem. In C++ we set up a List object which was a
> "linked list" of Node objects and each Node object contained a Word
> object. Each object has it's own methods, and we set up operator
> overloading to dump objects into ostreams (STDOUT), etc.

The intent of this assignment, I presume (hope?), is to help you
understand how much libraries (such as the STL) help ... when you get
there in future classes.  :)

Happy New Year!
George.


More information about the Omaha-pm mailing list