Sun751 has asked for the wisdom of the Perl Monks concerning the following question:

I am having problem using '"' actually I want "" between $addline in below code:
print "<RESOURCE Id=$addline $$HRR_resource{$addline}</RESOURCE>}\n";
as a output I want it to be like this: <RESOURCE Id="AAA" BBB</RESOURCE> if $addline = AAA and $$HRR_resource{$addline} = BBB any suggestion???

Replies are listed 'Best First'.
Re: printing output with ""
by Marshall (Canon) on Jun 23, 2009 at 04:16 UTC
    In general to have a " interpreted literally just "escape it" by putting a \ backslash in front. There are a myriad of ways of "quoting" in Perl.
Re: printing output with ""
by bichonfrise74 (Vicar) on Jun 23, 2009 at 04:11 UTC
    Is this what you want?
    #!/usr/bin/perl use strict; my $addline = 'AAA'; my $HRR_resource = { $addline => 'BBB' }; print qq!<RESOURCE Id="$addline" $$HRR_resource{$addline}</RESOURCE>}\ +n !;
Re: printing output with ""
by ambrus (Abbot) on Jun 23, 2009 at 07:30 UTC
    my $addline = "AAA"; my $HRR_resource = {$addline, "BBB"}; use XML::Twig; my $e = XML::Twig::Elt->new("RESOURCE", {"Id", $addline}); $e->set_text($$HRR_resource{$addline}); my $t = XML::Twig->new(pretty_print => "indented"); $t->set_root($e); $t->flush;

    Adds the quotes automatically.