#!/usr/bin/perl -w
use strict;
use warnings;
use Class::Struct;
struct System => {
Name => '$',
};
my $system = new System;
$system->Name("Server1");
my $strout1 = qq{Server is ${$system->Name}\n};
my $strout2 = "Server is \"".$system->Name."\"\n";
print $strout1;
print $strout2;
results in:
Can't use string ("Server1") as a SCALAR ref while "strict refs" in use at test.pl line 14.
I want to be able to use qq and deref $system->Name correctly. Can anyone explain where i am going wrong?
Method calls aren't interpolated in double quoted strings, but dereferences are. If you want to interpolate the result of the method call, you must dereference a reference to it:
my $strout1 = qq{Server is ${\$system->Name}\n};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With