Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Request translation into Perl

Name: Anonymous 2006-06-26 10:56

I'm testing something, and I'm stuck trying to write a Perl equivalent of this function because Perl's syntax is made of ugly, rudimentary, hack and fail. Could you please show me how to do this very simple thing in Perl?

function f($i = 1, $r = 17) {
    return --$r <= 0 ? null : array($i => f($i + 2, $r), $i + 1 => f($i + 3, $r));
}

Thanks!

Name: Anonymous 2006-06-27 8:51

>>11
Perl 5's lack of formal function parameters allows you to do certain things more easily than php.
 - Modifying the values of @_ modifies the values used to call the function, like pass by-ref without needing special syntax.
 - You can turn the arguments into some number of scalars followed by an array. (In PHP, you have to save the function args in a variable and manually shift your arguments off it)
 - If you don't care about 0 being false, you can just use || for default args instead of that weird df sub. (PHP's or is retarded and only returns 0 or 1, making it much less useful, but that's for another rant!)
 - Perl's fat-comma syntax lets you simulate named parameters without having to put array() around every call.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List