On Fri, 27 Nov 2009, Mark_Galeck wrote:
> Hello, the following question I posted on perl.beginners but for a few
> days there is no response, so maybe it is not a beginners question?
> Nah, it must be :)
I cannot provide brief explanations, but this may help:
> --------------------------------
> If I can do this:
>
> $ref = \...@foobar;
> print @$ref;
>
> then why can't I do this:
>
> print @\...@foobar;
use: print @{ \...@foobar };
It seems to work.
> ------------------------------------
> I have this kind of problem often, let me give another example, I
> think it is similar, let me know if not.
>
> Why are all the printouts different:
>
> @foobar = ();
> print \...@foobar; #prints as reference to ARRAY
This is OK.
>
> $foobar = \();
> print $foobar; # prints as reference to SCALAR
use: $foobar = []; print $foobar;
and you get the output as before.
> print \(); #prints as array of references to SCALAR, in this case
> empty array
use: print [];
For creating a reference to a literal array, use: [1, 2, 3] instead of
\(1,2,3)
Cheers,
--Vlado