2 ms·
By named parameters, i mean: sub double($value) { return $value * 2; } Which you can't write in Perl (or at least couldn't in 1998). You have to wri
by twic 6y ago
By named parameters, i mean:
sub double($value) {
return $value * 2;
}
Which you can't write in Perl (or at least couldn't in 1998). You have to write this:
sub double {
my $value = shift(@_);
return $value * 2;
}
"Named parameters" probably isn't the right name. This is such a basic feature of programming languages that i don't even know what it's called.
- cutler 6y ago"Unrolling @" was a common bugbear amongst Perl programmers and caused a few I know of to leave for Ruby or Python. Normal, parenthesised parameters were considered experimental until not that long ago so is it any wonder Perl failed to compete with Ruby and Python?
- jandrese 6y agoThe term you are looking for is "pass by reference". Perl does not have pass by reference, you have to use pointers if you want to do it. It will even go so far as to duplicate an entire array or hash you pass to a function, which can surprise novice Perl programmers when they build a giant data structure and start passing it around only to discover their program running slowly. Or worse, finding their changes to the structure being undone when the function exits.
- cygx 6y ago> The term you are looking for is "pass by reference". Nope, just parameter declarations. I also kind of doubt the by-value semantics will surprise anyone the way you describe: If you pass things by value without explicitly taking a reference, the structure (arrays and hashes, specifically) will be flattened into the argument list. If you're unaware of this, things will probably go wrong long before you've had time to be surprised by stuff getting copied...
- jandrese 6y agoIt can certainly catch C programmers who are used to arrays devolving to pointers in the background when passed as parameters.