How did you learn this type of effiecient coding?
It's basically the principle of "informed, constructive laziness": you know what needs to be done, you figure out the minimum number of steps required to get it done, and you structure the program in such a way that you never write a given chunk of code (e.g. an "if" condition or quoted string or any multi-step procedure) more than once. For me, a key step is to document (in coherent, human language) what the code is going to do first, then write the code according to the documentation.
When $dispmode equals 3 ..., it doesn't show the coordinates as an ordered pair
I gather you mean it's not putting parens around the "x,y" in the last column of the table. If it's really important to get the parens in there, I guess I'd elaborate that sub a little:
sub { my @cels = split( /,/, $_[0], 8 );
$cels[7] = '('. $cels[7] .')';
print '<tr><td>'. join('</td><td>',@cels) ."</td></tr>\n" }
How would I need to change the code if I wanted to add another display option, such as filtering by name?
You could filter entries as you read from the file, by altering the grep condition that I suggested for skipping blank lines; e.g. if you add a cgi param like "$name_pattern" (which the user can set to a string or leave blank), you can say:
my $match = ( $name_pattern =~ /^(\w+)$/ ) ? $1 : "\\S":
my @data = grep /$match/i, <FILE>;
(updated to fix typo in sub snippet; also switched to using a regex capture in the second snippet, in accordance with the standard idiom for untainting data) |