escaping - Using double quotes in Perl script -


Anyone can help solve it:

  Use strict; Use warnings; My $ teststr = "\" abcd \ ""; Print "\ nTestStr: $ teststr \ n"; `Echo" $ teststr "& gt; & Gt; \ / Home \ / folder \ samplequotes.txt`;  

Output of the above program:

  $ perl quotes1.pl TestStr: "abcd" $ cat samplequotes.txt ABCD  

The problem I am facing is that double quotes in the string are not found in the text file

Ideally, the content of the samplequotes.txt file should be:

< Pre> "abcd"

Can anyone tell me what problem would be here ??

Your problem is mixing Pearl and Shell; There are two identical, but not equal sets of quotes from the conventions, and it is difficult to understand the conversation between them (because you both have to understand separately, as well as how they interact).

Extension of the Perl:

`resonance '$ teststr" & gt; & Gt; \ / Home \ / folder \ samplequotes.txt`;

In:

  echo "" ACD "" & gt; & Gt; /home/folder/samplequotes.txt  

and the shell treats adjacent double quotes as empty, so you get the abcd in the file if you go to Shell If you do not want to interpret double quotes, write:

  `echo '$ teststr' & gt; & Gt; / Home / folder / samplequotes.txt`;  

The Shell is to be viewed as:

  echo '' abcd '' & gt; & Gt; /home/folder/samplequotes.txt  

However, to resonate in this way is not just good for running a shell; It would be more sensible to open the Pearl file and add the output and then close the file.

  {Open my $ FH, '& gt; & Gt; ', "/ home / folder / sample quotes" or die; Print $ FH $ teststr; }  

The braces file limits the handle of the handle to four lines of code, and when the handle of the file goes out of the scope, it automatically closes the file.

The backslash in the file name in your code is all too meaningless, Pearl removes them (AAAICT) so that the shell can not be found.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -