Re: How to handling string contains single quote and double quote
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 28 Apr 2007 11:45:35 GMT
vikrant <vikrant.kansal@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 in Perl, and print the line to the file in Perl.
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 ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- Follow-Ups:
- References:
- Prev by Date: Re: How to handling string contains single quote and double quote
- Next by Date: FAQ 4.33 How do I pad a string with blanks or pad a number with zeroes?
- Previous by thread: Re: How to handling string contains single quote and double quote
- Next by thread: Re: How to handling string contains single quote and double quote
- Index(es):
Relevant Pages
|
|