Re: How to handling string contains single quote and double quote



On Apr 28, 4:45 pm, j...@xxxxxxxxxxx (Jens Thoms Toerring) wrote:
vikrant <vikrant.kan...@xxxxxxxxx> wrote:
On Apr 28, 3:26 pm, Paul Lalli <mri...@xxxxxxxxx> wrote:
On Apr 28, 4:41 am, vikrant <vikrant.kan...@xxxxxxxxx> wrote:

system("echo '$Date;$String_Value' > data.txt");

Why are you calling a system command to do the echoing? Just open the
file for writing inPerl, and print the line to the file inPerl.
Then you don't have to worry about any escaping of quotes.

open my $fh, '>', 'data.txt' or die "Cannot open file: $!";
print $fh "$Date;$String_Value\n";
close $fh;

Paul Lalli
Thanks for the information.Actually,the code is a part of a
function,which called again and again.So,i thought that opening and
closing a file on each call may effect the performance.That was the
only reason of using the system command.

Actually, your approach uses a lot more resources and time.
The system() function must create a new process, which in turn
executes a shell to deal with the command you sent to system().
And the file must be opened and closed again anyway, but now
the shell will do that. So all the system() call does is add
overhead, saving you nothing at all (beside making it harder
to check for errors).
Regards, Jens
--
\ Jens Thoms Toerring ___ j...@xxxxxxxxxxx
\__________________________ http://toerring.de

Hi JensThoms,

Thanks for sharing the information.It is very helpful to me.

Regards,
Vikrant

.