Jazz-jj has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I have a script accepting XML input through STDIN.

$xmlPayload = do { local $/; <STDIN> }; `echo "$xmlPayload" >> /temp/MyLog.log`;
the initial XML looks like this:

<param name="assignedgroup">fraud</param>
<param name="assigneduser">username</param>
<param name="severity">minor</param>
<param name="title">Bad Fraud Thing</param>
but when this same input is taken in through STDIN it ends up like this:

<param name=assignedgroup>fraud</param>
<param name=assigneduser>username</param>
<param name=severity>minor</param>
<param name=title>Bad Fraud Thing</param>
you can see the double quotes are stripped. I'm not sure where this is happening at. I take it in through STDIN and just echo out to a file and the double quotes are gone. I've taken this same input and passed it to a Python script and verified the double quotes are present in the same output file. So the only thing I can come up with is STDIN is stripping it.

is this a known issue? are there arguments to stop it from stripping the double quotes?
thanks!

Replies are listed 'Best First'.
Re: XML input through STDIN
by huck (Prior) on Jun 03, 2017 at 05:38 UTC

    echo is what is stripping the quotes,but probably not where you expect

    try writing directly to a file rather than using echo

    open (my $out,'>>',/temp/MyLog.log) or die 'cant open'; while (<STDIN>) { print ;}

    Added:

    To understand what echo is doing paste this at a command line

    echo "<param name="assignedgroup">fraud</param>"
    What you get back is
    <param name=assignedgroup>fraud</param>

      > echo is what is stripping the quotes

      Well, in fact, it's the shell that strips the quotes. Both single and double quotes are special for the shell and are removed during "Quote Removal" as the last step after all the expansions (see bash).

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
        Yes it's the shell that strips the quote but it's probably not bash (entering pedantic mode now).

        I don't really know about other systems, but on unixy-systems the shell used is /bin/sh which on my Debian is a link to dash.

      GAH!!! you are correct sir. I couldn't wait and did it just now. Happened exactly as you said. Opening a file and writing instead of echo had the right format.

      can't say thanks enough.