Re: How to handling string contains single quote and double quote
- From: vikrant <vikrant.kansal@xxxxxxxxx>
- Date: 28 Apr 2007 04:35:24 -0700
On Apr 28, 3:26 pm, Paul Lalli <mri...@xxxxxxxxx> wrote:
On Apr 28, 4:41 am, vikrant <vikrant.kan...@xxxxxxxxx> wrote:
Hi,
I facing a problem in saving a string contains single and double quote
into a file .The string look like the following:-
Example:-
Developer's community "com.lang.perl"
--------------------------------------------------------
The part of Code is:-
#!/bin/perl -w
use strict;
my $Date="10-09-2007";
system("echo '$Date;$String_Value' > data.txt");
----------------------------------------------------------------------------------------
Here,the $String_Value Variable store the string which i have
mentioned above.
I cannot put the slash( \ ) before the double quote's because in my
case value of input string is dynamic.
Also,I know putting a slash before double quote do not solve my
problem because single quote is left which will create the problem.I
get to know about this when i put slash before the double quote's.
The error coming on screen is:-
------------------------------------------------------------------------------------------------
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
-----------------------------------------------------------------------------------------------------
So,please tell me how do i handle this type of input.
I apologize if someone already asked this question earlier.
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.
Comments are most welcome.
Thanks and Regards,
Vikrant
.
- Follow-Ups:
- Re: How to handling string contains single quote and double quote
- From: Jens Thoms Toerring
- Re: How to handling string contains single quote and double quote
- References:
- How to handling string contains single quote and double quote
- From: vikrant
- Re: How to handling string contains single quote and double quote
- From: Paul Lalli
- How to handling string contains single quote and double quote
- Prev by Date: Re: How to handling string contains single quote and double quote
- Next by Date: Re: How to handling string contains single quote and double quote
- 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
|
|