Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Code challenge: array subrange

by Jasper (Chaplain)
on Jan 13, 2005 at 12:49 UTC ( [id://421952]=note: print w/replies, xml ) Need Help??


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}} }]; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://421952]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found