Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday November 15, 2002
12:16 PM

Code Review

[ #8966 ]

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),$_] }

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Looks like the substr($_,3,2) in the Schwartzian transform isn't used at all. Not a bug, but a no-op.

  • 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.