Hacker News new | ask | show | jobs
by aaronblohowiak 5633 days ago
Why require context-dependent sigils when you don't need to?

Eliminate the unnecessary.

2 comments

for the same reason strcmp() returns not just a -1,0, or 1, but a "distance" between the two strings being compared. A function or syntax has multiple uses if additional information is available to the programmer.

Example:

@array = qw(1 2 3); $length = @array;

print $length;

By allowing a non scalar to take an implicit scalar form, we have an extremely useful and quick way to get the length of an array. Nothing that difficult to replace with a len() call, but it's language features like these that make perl ($length = @_ may be the most useful of all) so handy for quick hacks.

I guess my problem with something like that is that conceptually it doesn't make much sense. There's no obvious reason why assigning an array to a scalar variable would give its length – it doesn't really feel clear or elegant, just unexpected.
Why require context-dependent sigils when you don't need to?

That's a circular argument. So is "Why not require them when you need them?"