title: convert yaml to json in bash using perl
body: <p>I am trying to convert a yaml-string to json in bash using perl (unfortunately it has to be like this) and am having problems.
  It works when I write it to a temporary file and convert that but unfortunately I do not have enough perl-experience to change it to work with a bash-variable to perform identically.
  I need to do that because I want to convert many files quite often and always creating temporary files is slow/inefficient and in my case also a security issue.</p>
  
  <p>This is the command that is working with the temporary file:</p>
  
  <pre><code>jsonfile=$(perl -MYAML::XS=LoadFile -MJSON::XS=encode_json -e 'for (@ARGV) { for (LoadFile($_)) { print encode_json($_),"\n" } }' ${tempfile} )
  </code></pre>
  
  <p>can I somehow change this to something along this?</p>
  
  <pre><code>jsonfile=$(echo "${yaml_string}" | perl .....)
  </code></pre>
  
  <p>I slightly changed the parameters and tried something like this but the output is quite different and not usable:</p>
  
  <pre><code>jsonfile=$(echo "${yaml_string}" | perl -MYAML::XS=Load -MJSON::XS=encode_json -e 'for (&lt;&gt;) { for (Load($_)) { print encode_json($_),"\n" } }')
  </code></pre>
  
  <p>Any assistance with this would be greatly appreciated.</p>