in reply to Re: Sort based on a delimited field in array elements without affecting original array elements
in thread Sort based on a delimited field in array elements without affecting original array elements

Speaking of Schwartzian transform, is there a simple way to define a ST-method and then apply it to different circumstances? The problem is felt when trying to sort two different kinds of things, yet without having to write the ST again and again, each time with a minor change.

Consider:
my @blobs = map { $_->[0] } sort {$a->[1] cmp $b->[1] } map { [$_, $_->property_foo()] } @blob_list; my @flobs = map { $_->[0] } sort {$a->[1] cmp $b->[1] } map { [$_, $_->function_bar()] } @flob_list;
You can do this with C++ templates. How, though, in Perl, though without using eval or sacrificing the value of warnings when passing bad function names?
  • Comment on Re^2: Sort based on a delimited field in array elements without affecting original array elements
  • Download Code

Replies are listed 'Best First'.
Re: Re^2: Sort based on a delimited field in array elements without affecting original array elements
by I0 (Priest) on Mar 01, 2002 at 23:47 UTC
    sub ST(&@){ my $metric=shift; map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {[$_,&{$metric}]} @_ }