Code Review

Ovid on 2002-11-15T17:16:34

Chatting with a nice guy and agreed to a quick code review. I stumbled across the following, presented without comment (note: the author tells me that the code works and has no known bugs).

@data =
  map  { $_->[1] }
  sort { $a->[1] cmp $b->[1] }
  map  { [substr($_,3,2),$_] }
    @in_data;

foreach my $line ( @data ) {
  my $key = substr $_,3,2;
  # more code here


Cute

Theory on 2002-11-15T20:21:46

Looks like the substr($_,3,2) in the Schwartzian transform isn't used at all. Not a bug, but a no-op.

Re: Code Review

dws on 2002-11-16T00:11:06

If the intent is to sort on a chunk out of the middle of the strings, then either they've gotten very lucky with their data, or nobody has noticed that things aren't in order. Or perhaps they started down the road of extracting a chunk of text once, rather than N^2 times, and got where they are now through incomplete refactoring. Hard to tell without seeing more code.