foo([]);
See References for details.
| [reply] [d/l] |
... pass an anonymous empty array to a subroutine:
&foo(qw());
A bit OT: I would say a better (because simpler) way to do this would be:
foo();
What would be the purpose of the empty qw() call?
BTW: I would also advise against using & sigils for function calls in "modern" (i.e., post-4.xx version) Perl code; they will usually do no harm, but may introduce subtle bugs in certain cases (usually involving Prototypes — but let's just not involve prototypes!).
Give a man a fish: <%-(-(-(-<
| [reply] [d/l] [select] |
Hi,
Here is how I can pass an anonymous empty array to a subroutine:
&foo(qw());
Here you are not passing anything. So obviously in function foo() @_ will be empty, it does not mean you are passing anonymous empty array.
If you think you are passing anonymous empty array, it should be a first element in @_array, print as $_[0] you will get 'undef', as suggested by choroba use square bracket [] to pass empty anonymous array, then print $_[0] in foo() you will get a refernce to a anonymouse array as []
All is well. I learn by answering your questions...
| [reply] [d/l] [select] |
How about, within the function, if the parameter-value received is undef, replace it with an empty-array ref and proceed? | [reply] |