in reply to Re: Printing accessor methods in here documents
in thread Printing accessor methods in here documents

Wow you guys are quick, thanks.
Now i'm scratching my head trying to parse that
So tell me, whats going on with @{[ ]}

Replies are listed 'Best First'.
Re^3: Printing accessor methods in here documents
by Zaxo (Archbishop) on May 06, 2005 at 19:17 UTC

    Similarly, if you'd wanted $self->blat() evaluated in scalar context, you could say ${\$self->blat()}.

    (Added) !1++, you're exactly right.

    After Compline,
    Zaxo

      Uh, not exactly. It actually evaluates in list context but treats the return as if it were in scalar. Like so:

      #!/usr/bin/perl -wl my @x = qw[ a b c d ]; sub x { print wantarray ? "list context" : defined(wantarray) ? "scalar context" : "void context"; @x } print "@{[ x() ]} - ${\ ( x() )} - ${\ ( @x )}"; __END__ list context list context a b c d - d - d
Re^3: Printing accessor methods in here documents
by cog (Parson) on May 06, 2005 at 19:09 UTC
    The [] creates a reference to a list. The @{ } dereferences that list, so you get basically the same thing you've put in it (kind of).

    The trick here is: inside a string, @{[ ]} gets whatever is inside it to be evaluated as an array.

    Your first version was having $self being parsed all by itself (try opening your code with Vim, having syntax on; Vim's syntax will catch that for you).

    And don't forget to use strict. And probably to create an account here, too, so we can all say "welcome" :-)