The prototype is ignored when & is used.
use strict; use warnings; sub testing(\@) { my ($arg) = @_; print("First argument: ", $arg, "\n"); $arg->[5] = 'e'; } my @a = qw( a b c d ); print("Test 1:\n"); testing(@a); print("\n"); print("Test 2:\n"); &testing(@a); print("\n"); __END__ output ====== Test 1: First argument: ARRAY(0x1ab2780) Test 2: First argument: a Can't use string ("a") as an ARRAY ref while "strict refs" in use at ! +.pl line 8 .
It also varies the behaviour of function calls with no parens:
sub testing { print("[@_]\n"); } sub test1 { testing; } sub test2 { &testing; } print("Test 1:\n"); test1(); print("\n"); print("Test 2:\n"); test2('moooo'); print("\n"); __END__ output ====== Test 1: [] Test 2: [moooo]
In reply to Re^3: Breaking out of an 'if'
by ikegami
in thread Breaking out of an 'if'
by jpfarmer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |