in reply to Printing accessor methods in here documents

I think this would do the trick:

print <<HERE I want blat to be the $blat not @{[$self->blat()]} \n HERE

O:-)

Two other things:

1) You're not using strict!!! You should! :-)

2) Why are you using \n inside a heredoc? Why not just hitting return?

Replies are listed 'Best First'.
Re^2: Printing accessor methods in here documents
by Anonymous Monk on May 06, 2005 at 19:04 UTC
    Wow you guys are quick, thanks.
    Now i'm scratching my head trying to parse that
    So tell me, whats going on with @{[ ]}

      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
      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" :-)