perl pra wrote:
>
> On 10/26/06, Mumia W. <[EMAIL PROTECTED]> wrote:
>>
>> On 10/26/2006 05:47 AM, perl pra wrote:
>> > hi ,
>> >
>> > I want to pass a command argument to perl script with double quotes ("
>> );
>> >
>> >
>> > below is my scenario
>> >
>> > my xml file is something like this ..
>> >
>> >
>> > <root>
>> >
>> > <reff>
>> >    <var1>123</var1>
>> >     <var2>this is my name</var2>
>> > </reff>
>> > <reff>
>> >    <var1>234</var1>
>> >     <var2>this is others name </var2>
>> > </reff>
>> > </root>
>> >
>> > my perl script is something like this
>> >
>> >
>> >
>> > my $xmlfile = "./samp1.xml";
>> >         my $ref = eval { XMLin($xmlfile) };
>> >
>> > if ($@){
>> >
>> >    print "XML Read ERROR";
>> >
>> > } else {
>> >
>> > foreach my $item (@{$ref->{reff}}) {
>> >
>> > system("perl C:\\Document and settings\\Desktop\\search.pl -n
>> > \"$item->{var2}\"");
>> >
>> > the search.pl file consists of .
>> >
>> > print "AGRV[1]";
>> >
>> >
>> >
>> > my out put is
>> >
>> > this is my name
>> >
>> > this is others name
>> >
>> >
>> >
>> > i understand that the string is getting passed to the perl script with
>> out
>> > quotes ..
>> >
>> >
>> >
>> > just a straight string is geeting passed (like this  this is my name)
>> >
>> > but i need to send the entire string including  double quotes to the
>> > script.,something like this ( "this is my name")
>> >
>> > Waiting for your solutions....
>> >
>> > thanks in advance
>> >
>> > perl guy
>> >
>>
>>
>> Under Linux, you could separate the arguments in the system() call, like
>> so:
>>
>> system('perl','C:\\Document and settings\\Desktop\\search.pl',
>> '-n', '"' . $item->{var2} . '"');
>>
>> Obviously, you're not running under Linux, so try this:
>>
>> system(qq{perl "C:\\Documents and Settings\\Desktop\\search.pl" -n
>> "\\"$item->{var2}\\""});
>>
>> I'm unsure of how many backslashes you need to escape those quotes.
>
> I tried this but no luck..
>
> let me tell me explain my problem in detail to you guys so that you  may
> give me the apt solution.
>
> i have perl script that searches given string (the string should be passed
> in command line argument),
>
> The string should be sent to the script with double quotes attached to it
> .(if the string is sent to the script with quotes the spaces in the string
> are taken as AND other wise the spaces are taken as OR)
>
> I will write all these strings in xml file with quotes...
>
> I have to retrive these strings and then send to the script ....
> (i am sending the string to script something like this
>  system("perl C:\\Document and settings\\Desktop\\search.pl -n
> \"$item->{var2}\"");
>
> If i send the string as above the script is not taking the double quotes ..
> it searches with the plain string (with out double quotes and produce the
> wrong results .)
>
> hope that explains the problem i have..
>
> Is there any other way to solve the problem ...other than the way which
> i am
> employing..
>
> I am stuck up. please give me some solution.
>
> Waiting for solutions..
>
> Thanks in advance
> Perl Pra

(Please bottom-post your replies, otherwise long threads can easily become
incomprehensible. Thank you.)

First of all that's more simply written as

my $search = 'C:\Document and settings\Desktop\search.pl';
system(qq(perl $search -n "$item->{var2}"));

and if you have ActiveState Perl installed with file types associated properly
then you can just put

system(qq($search -n "$item->{var2}"));

Do you have control over the search program? Because it is being passed all the
information it needs and throwing it away. If I write

system(qq($search -n "a b c" d e f));

then four parameters will be passed - 'a b c', 'd', 'e', and 'f'.

Presumably what the search program does is to mash them together into a single
string giving just 'a b c d e f', with no way of separating them again. I
recommend you fix this if at all possible.

Finally, if you must, this will solve your problem in the way you've approached
it:

my $search = 'C:\Document and settings\Desktop\search.pl';
system(qq(perl $search -n "\"$item->{var2}\""));

or to go closer to your original,

system("perl C:\\Document and settings\\Desktop\\search.pl -n \"\\\"$item->{var2}\\\"\"");


HTH,

Rob



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to