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?
what language is that? it looks like it's syntax has more ugly, hack, and fail than perl's...
Name:
Anonymous2006-06-26 12:04
Sorta looks like bash.
Name:
Anonymous2006-06-26 12:04
>>2
PHP. Wait until you see it translated into Professional Enterprise... uh, I mean Hacker Perl.
Name:
Anonymous2006-06-26 12:07
Oh, and your implementation is silly. It's exactly the same sort of silliness as a naive implementation of good old fibonacci. Recursion is great and all but you have to learn when not to use it.
Name:
Anonymous2006-06-26 17:40
I fail to see the point too as it can very easily be computed directly without resorting to atrociously inefficient recursion.
You can't set default function values in perl :
sub f { $_[1] <= 0 ? null : [$_[0] => f($_[0]+2, $_[1]-1), $_[0]+1 => f($_[0]+3, $_[1]-1)]; }
Name:
Anonymous2006-06-26 19:13 (sage)
>>6
Thanks, that's much clearer than the PHP version.
Name:
Anonymous2006-06-26 21:10
Wow I didn't know you fags didn't perl. Now I can't trust any of you when you say it sucks simply because you are obviously ignorant
sub df { return defined($_[0])?$_[0]:$_[1]; }
sub f {
my ($i,$r) = (df($_[0],1),df($_[1],17));
return --$r <= 0 ? undef : { $i => f($i + 2, $r), ($i + 1) => f($i + 3, $r) };
}
or
sub f {
my $i = defined($_[0])?$_[0]:1;
my $r = defined($_[1])?$_[1]:17;
return --$r <= 0 ? undef : { $i => f($i + 2, $r), ($i + 1) => f($i + 3, $r) };
}
>>2
PHP. No, it's far nicer than Perl, but I used ?: .
>>5
It's not meant to be fast, it's meant to compare something and do it that way.
>>8
That's why I didn't bother with Perl. Don't you feel something reeks in
sub df { return defined($_[0])?$_[0]:$_[1]; }
sub f {
my ($i,$r) = (df($_[0],1),df($_[1],17));
Name:
Anonymous2006-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.
Name:
Anonymous2006-06-27 9:35
>>12
Assembly allows you to do certain things more easily than PHP and Perl.
Admit it; we can say Perl is better than PHP in certain things (like ||, well said) but this is not one of them. Perl functions are a hack the kind you find in shell scripting; they are syntactically terrible, you have to repeat the same patterns by hand, default values are verbose, they are terrible for documenting, and it just feels like a kick in the stomach. You know, I wanted to learn a language for quick shell hacks, and started with Perl. When I reached functions and "my" variables, I switched over to PHP.
Python's model is even more elegant: you have named parameters, defaulted parameters, callee can receive the remaining parameters/named parameters in a list/hash and caller can send them from a list/hash as parameters/named parameters,
Name:
Anonymous2006-06-27 9:52
$%@#(&%$^)*@#)($hello, world$%#(*@#^*!
lol perl
Name:
Anonymous2006-06-27 10:20
>>13
What's wrong with 'my'? It's exactly the same as C's auto variables and javascript's 'var' variables. The default scope is global instead of local. Big deal...
Name:
Anonymous2006-06-27 11:45
>>15
You already answered yourself: the default scope is global, like JavaScript (unlike C). This is retarded. Think about it. It's the main reason why you want to use strict. Use strict in a highly dynamic, scripting, informal language is kind of a paradox brought by a poor design. You don't need that in Python or PHP, for example, even if PHP is not a great example of scoping.
Name:
Anonymous2006-06-27 13:22
So wait back on topic:
Perl or Python?
Name:
Anonymous2006-06-27 15:41
A. Your function is ugly.
B. Perl doesn't do default values very nicely because it handles functions differently (since perl can do anonymous functions properly I'd argue that PHP's idea of a function is a joke)
C. You don't need "my". My declares scope so you should use it
D. PHP's array is absolute bullshit and your code expresses that
E. In perl we are using hashref
F. Your programming should reflect what you mean, not just that it fits on 3 lines
G. 16 is an absolute idiot. scope matters and spelling matters. In C your declaration declares scope, if you don't use my you aren't declaring the variable.
H. 4chan proves yet again that /prog/ is full of idiots.
sub f {
my ($i,$r) = @_;
$i = defined($i)?$i:1;
$r = defined($r)?$r:17;
--$r;
return undef if ($r <= 0);
return {
$i => f($i + 2, $r),
($i + 1) => f($i + 3, $r)
};
}
Name:
Anonymous2006-06-27 21:39
what the hell is the point of this data structure anyway?
Name:
Anonymous2006-06-28 3:27
>>18 since perl can do anonymous functions properly I'd argue that PHP's idea of a function is a joke
1. How often are you going to use functions and anonymous functions? PHP is a better tradeoff than Perl.
2. Python supports closures and anonymous functions plus default values plus list parameters plus named parameters plus list and hash call plus a decent syntax.
You don't need "my". My declares scope so you should use it
What? If you don't use my, you'll get global variables, right?
PHP's array is absolute bullshit and your code expresses that
I'm stunned at your powerful arguments why PHP's array is bad.
Your programming should reflect what you mean, not just that it fits on 3 lines
And you're trying to defend Perl with this? Perl almost invented oneliners and obfuscation itself.
16 is an absolute idiot. scope matters and spelling matters. In C your declaration declares scope, if you don't use my you aren't declaring the variable.
Ever tried a good language, like Python?
And your code is fucking ugly.
>>19
Testing memory taken by different dictionary implementations.
Just because Python might (for some definitions of might) be a betterlanguage than Perl does not mean that PHP isn't a shitty language. The two issues are unrelated.
Name:
Anonymous2006-06-28 9:52
>>24
I was making two points, my dear Perl fanboy: 1. PHP is better at what's most important, and 2. Python is a better solution to both anyways.
You are incredibly stupid. HURR ANONYMOUS FUNCTIONS WHO USES THOSE. Maybe everyone who comes from a functional programming background. Maybe people who care about closures, maybe people who care about doing anything more complex than formatting some poor HTML. What do you think ruby is all about? Those blocks are basically anonymous functions.
Python guy: @_@ Irrelevant and pointless. This thread isn't about you. It is about how PHP users are ignorant about programming.
Name:
242006-06-28 20:36
>>25
I'm not the same guy, nor do I particularly like Perl (or Python for that matter).
Sorry to bust your bubble.
Name:
Anonymous2006-06-29 3:40
>>26 HURR ANONYMOUS FUNCTIONS WHO USES THOSE.
I use those. But I use named functions 90% of the time.
What do you think ruby is all about? Those blocks are basically anonymous functions.
I know about them.
Name:
Anonymous2006-06-29 21:02
WOW YOU GUYS DEFINATELY SHOWED THAT PERL GUY... THAT YOU ARE STUPID.
Name:
Anonymous2006-07-02 14:59
>>29
And what did you achieve with those caps-locks?