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



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
.



Relevant Pages

  • Re: Question about system call
    ... P> If memory serves me, back ticks are only needed inside a system command ... P> for UNIX commands and regular ticks specifying the system command within ... P> the Perl script. ...
    (perl.beginners)
  • Re: help chdir UNC path ( newbie )
    ... is a feature of CMD.EXE and has nothing to do with Perl). ... > Also CMD.EXE will interpret your command as a request to run a program ... the string doesn't get passed to the system command. ...
    (comp.lang.perl.misc)
  • Re: SYSTEM command problem
    ... I can run the script from the website and it creates the file fine. ... But the last line of code runs a SYSTEM command that calls Blat.exe and ... Perl will tell you what's wrong - if you ask it to. ... Another place to look for clues would be blat.exe's error log, ...
    (comp.lang.perl.misc)
  • Re: System, shell question
    ... > I am a beginner to perl and I have a question ... > execute a system command, ... > and the $cmd which is a prog takes another program ...
    (perl.beginners)
  • Re: Meaning of ` signs
    ... > Hey again all. ... I have progressed a great deal with the basics of perl. ... `` executes the enclosed text as a system command and returns ...
    (comp.lang.perl.misc)