Here document as method parameter



Hi all,

Is there any way to pass here document string as method parameter?

Suppose we have a demo object:

#########################
package Demo;

sub new {
bless {};
}

sub output {
my $self = shift;
print STDOUT shift;
}
#########################

I have tried two kinds of calling style:

1).
#########################
my $demo = Demo->new();
output $demo <<'EOF';
main()
{
printf("hello world\n");
}
EOF
#########################
This works fine.

2).
#########################
my $demo = Demo->new();
$demo->output <<'EOF';
main()
{
printf("hello world\n");
}
EOF
#########################
Perl will complain for syntax error, but it looks more conventional for
me.

Any help will be appreciated.

.



Relevant Pages

  • Re: Here document as method parameter
    ... Suppose we have a demo object: ... bless; ... print STDOUT shift; ...
    (perl.beginners)
  • Re: Threads and OO Question
    ... > " bless is not supported on shared references. ... sub increment { ... package MyPackage; ... my $class = shift; ...
    (comp.lang.perl.misc)
  • Sharing object between threads - howto?
    ... package PlugIn::SuperSnoop; ... sub startThread { ... bless is not supported on shared references. ... bless will only bless the thread local reference and the blessing will not propagate to the other threads. ...
    (comp.lang.perl.misc)
  • Re: How to overload the constructor?
    ... in the child class: ... sub new ... The reference becomes an object of that class at the bless ... If the child's constructor has no ...
    (perl.beginners)
  • Re: DESTROY isnt called
    ... Ferry Bolhar wrote: ... bless shift, 'Later'; ... sub Later::DESTROY { ... bless, 'Later'; ...
    (comp.lang.perl.misc)