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

I have a text containing " backslashes etc (xml format).
printf grp "<test:tester username ="$id" group-name="$grp1"/>\n"
I am trying to print it to a text file but got w=errors. I tried to use the backslah but did not help. Any ideas? I tied to put into a variable and then print like this:
$test = "/<test:test1 username=". $id ."/" group-name=/"". $grp1."//> +";

Replies are listed 'Best First'.
Re: writing text to a file
by kyle (Abbot) on Jul 17, 2008 at 18:30 UTC

    If you're not using formats, I'd use print instead of printf. If you've got quotation marks in your quoted string, try using qq. If "grp" really is a filehandle you opened with open or something, I'd recommend putting it in all caps, or better yet use a lexical filehandle.

    # open my $grp, '>', $out or die "Can't write '$out': $!"; print $grp qq{<test:tester username ="$id" group-name="$grp1"/>\n};
      Thanks a lot.. I tried the qq and it worked.