Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

@an_array=(1,2,3,4,5,6,7); &routine(\@an_array); sub routine { $ref=$_[0]; print @$ref; # That works # print (@($_[0])); # This would produce a compilation error! print @$_[0]; # And this doesn´t print anything! }
WHY?

Replies are listed 'Best First'.
Re: Dereferencing Subroutine Arguments
by merlyn (Sage) on May 17, 2000 at 20:16 UTC
    The canonical form of a dereference is to take the normal form:
    @FOO
    and replace the word (here FOO) with a block returning the reference:
    @{$a[0]}
    Only when the braces enclose a simple scalar variable (like $x) can you drop the braces. You don't have a simple scalar here, so the braces must remain on.
Re: Dereferencing Subroutine Arguments
by davorg (Chancellor) on Jun 21, 2000 at 12:47 UTC
    Your second example, (@($_[0])) doesn't work because you're surrounding the reference with 'round' brackets, not 'curly' brackets.