Re:A nice, little known C feature: Static array indices in p...
by leviathan on Monday February 18, 2013 @06:01PM
(#5241384)
Calling a sub with & has a special meaning, it exposes the current argument list @_ to the called sub. That's why you don't see it in most code.
[ Parent
| on HN ]
Re:A nice, little known C feature: Static array indices in p...
by drivers99 on Tuesday February 19, 2013 @11:59AM
(#5245388)
I did not know that. Interesting. However, it only works if you call the sub without parentheses like this: &foo
Calling it with parentheses like &foo() would make @_ empty inside of foo. (Or if you said &foo("whatever") it would pass that as @_ instead.)
sub while
{
print "@_\n";
&foo();
}
sub foo
{
print "@_\n";
}
&while("a","b","c");
produces: a b c
(blank line)
as the output, and sub while
{
print "@_\n";
&foo;
}
sub foo
{
print "@_\n";
}
&while("a","b","c");
produces: a b c
a b c
as the output. At any rate, back to the original topic: it still doesn't prevent new keywords from potentially colliding. Oh well.