in reply to Re^2: $_ functions vs argument-using functions
in thread $_ functions vs argument-using functions
I understand that the prototype sub f ($) {} makes sure f is called with exactly one argument.
Sorry, but that's not true:
#!/usr/bin/perl use strict; use warnings; sub f($) { print 'f called with ',0+@_,' arguments: ',join(', ',@_),"\n"; } sub g { print 'via g: '; &f; } f(42); &f(42); &f(); &f(42,99,333); g(42); g(); g(42,99,333);
Output:
f called with 1 arguments: 42 f called with 1 arguments: 42 f called with 0 arguments: f called with 3 arguments: 42, 99, 333 via g: f called with 1 arguments: 42 via g: f called with 0 arguments: via g: f called with 3 arguments: 42, 99, 333
See perlsub for what happens here, and why perl does not complain.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: $_ functions vs argument-using functions
by LanX (Saint) on Sep 10, 2013 at 10:30 UTC |