J
jab3
1st: I'm REALLY sorry for the previous empty post (if it makes it out).
I accidentally hit enter after subject.
2nd: Sorry for using Google Groups. I'm not at my normal computer.
3rd: I looked for the answer in this group and on the web, but couldn't
find what I'm looking for. I'm sure someone will immediately point out
15 references on their first query. Sorry.
Anyway, I'm having trouble figuring out how to call a method from an OO
module from within a string built around qq~ ~;. The reason for
building the string is that it's a web-based app, and I'm building HTML
that way. A simple example follows.
#
# MyTest.pm
#
package MyTest;
use strict;
use warnings;
sub new
{
my $class = shift;
$class = ref($class) || $class; # Just to be safe
bless { this => 'that'}, $class;
}
sub what_is_this
{
my $self = shift;
return $self->{this};
# I suppose I could say 'return shift->{this}', but
# I like a little flow
}
1;
-------------------------------------------------------------
#!/usr/bin/perl
#
# try_this.pl
#
use MyTest;
use strict;
use warnings;
my $what = new MyTest;
my $content = qq~
<p>I want the value of this: $what->what_is_this </p>
~;
print $content;
-----------------------------------------------------------
Output:
<p>I want the value of this: MyTest=HASH(0x8170c28)->what_is_this </p>
I tried dereference the method various ways just to see what happened.
One error was 'Can't use string ("that") as a SCALAR ref while "strict
refs" in use at ./try_this.pl line 8.'
So, could someone please tell me there is a way to call the methods
directly instead of sticking the values in variables outside the qq
string?
Or, what is the right way to go about this? Any help
would be greatly appreciated.
Thanks,
jab3
I accidentally hit enter after subject.
2nd: Sorry for using Google Groups. I'm not at my normal computer.
3rd: I looked for the answer in this group and on the web, but couldn't
find what I'm looking for. I'm sure someone will immediately point out
15 references on their first query. Sorry.
Anyway, I'm having trouble figuring out how to call a method from an OO
module from within a string built around qq~ ~;. The reason for
building the string is that it's a web-based app, and I'm building HTML
that way. A simple example follows.
#
# MyTest.pm
#
package MyTest;
use strict;
use warnings;
sub new
{
my $class = shift;
$class = ref($class) || $class; # Just to be safe
bless { this => 'that'}, $class;
}
sub what_is_this
{
my $self = shift;
return $self->{this};
# I suppose I could say 'return shift->{this}', but
# I like a little flow
}
1;
-------------------------------------------------------------
#!/usr/bin/perl
#
# try_this.pl
#
use MyTest;
use strict;
use warnings;
my $what = new MyTest;
my $content = qq~
<p>I want the value of this: $what->what_is_this </p>
~;
print $content;
-----------------------------------------------------------
Output:
<p>I want the value of this: MyTest=HASH(0x8170c28)->what_is_this </p>
I tried dereference the method various ways just to see what happened.
One error was 'Can't use string ("that") as a SCALAR ref while "strict
refs" in use at ./try_this.pl line 8.'
So, could someone please tell me there is a way to call the methods
directly instead of sticking the values in variables outside the qq
string?
would be greatly appreciated.
Thanks,
jab3