If I were a Perl maintenance coder, I might prefer something slightly more verbose (but only slightly).
But if I were using this example to wave at Java coders to convince them that Perl will save them grief, I would make it even more verbose, lest it reenforce a notion that Perl is overly cryptic. Past a point, "Look how small we can do this with Perl!" becomes a negative. Instead, present Java programmers with something more familiar.
Something like
A bit more verbose than what would automatically fly off the fingertips of a seasoned Perl hacker, but even with comments, it is less than a third the size of the Java example. AND it only uses control structures that a Java programmer should recognize. The only thing they might object to is the hidden use of $_.#!/usr/bin/perl -w use strict; my %frequency = (); # maps token -> count # for every line of every input file while ( <> ) { # for each token on the line foreach my $token ( split /\W/ ) { # increment the count for the token $frequency{$token}++; } } # print each token and its count foreach my $token ( sort keys %frequency ) { print "$token: $frequency{$token}\n"; }
(I don't know how TreeMap behaves, so the sort might need to be changed to sort on value.)
In reply to Re: Efficiency in maintenance coding...
by dws
in thread Efficiency in maintenance coding...
by eduardo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |