in reply to Code challenge: array subrange

First stab with no error checking
sub righter {$_[0]..$_[1],reverse(pop..pop)} sub array_range {
sub righter {$_[0]..$_1,reverse(pop..pop)}
$h = pop; @rel{ righter @{$h->{range}} } = @{$h->{arr}}; [@rel{ righter@{ $h->{subrange}} }] }
Well, I didn't really consider where I was putting the sub - moved it outside to appease demerphq ;).

Replies are listed 'Best First'.
Re^2: Code challenge: array subrange
by demerphq (Chancellor) on Jan 13, 2005 at 12:56 UTC

    You really shouldn't be declaring named subs inside of named subs in perl. Subs only nest properly in perl if the inner subs are anonymous.

    ---
    demerphq

Re^2: Code challenge: array subrange
by Jasper (Chaplain) on Jan 14, 2005 at 10:37 UTC
    And with range checking (just got around to this now)
    sub r {$_[0]..$_[1],reverse(pop..pop)} sub array_range { $h=pop; @rel{ r@{ $h->{range} } } = @{ $h->{arr} }; [grep { defined() ? $_ : die "out of range" } @rel{ r@{ $h->{subra +nge}} }]; }