Re: How to pass string in command line argument.




Perl Pra wrote:
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


On 10/26/06, Mumia W. <mumia.w.18.spam+nospam@xxxxxxxxxxxxx> 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.



--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>




------=_Part_63336_16565188.1162018376337--

Where is your code (make a small script - or scripts - in this case
that exhibits the problem you are having). You have been given two
solutions, have you tried those. I am running on a Windows machine and
at least one solution appears to work. For instance:

========== SCRIPT 1 =============
use strict;
use warnings;

my $item = "TEST QUOTES";
system(qq{p.pl "\\"$item\\""});

========== SCRIPT p.pl ============
use strict;
use warnings;

$a = shift;
print $a . "\n";

Ken

.



Relevant Pages

  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... You can set the working directory from within your Perl ... match for the "Citation:" etc string. ... The Perl Language and the Regular Expression Language are different ...
    (comp.lang.perl.misc)
  • my script crashes when I try to rename the file!
    ... OK, thanks, but the script does not seem to rename the files. ... You can set the working directory from within your Perl ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (perl.beginners)
  • Re: Perl script to extract data from webpage? (knucklehead newbie).
    ... Your $& is a special perl variable that represents the string matched by ... the last successful pattern match...which in the case of your example ... I have this running now using a script I found elsewhere, ...
    (comp.lang.perl)
  • Re: How to pass string in command line argument.
    ... > I want to pass a command argument to perl script with double quotes (" ... > just a straight string is geeting passed ...
    (perl.beginners)
  • Re: basic help to run an application from WSH
    ... The Run method requires at least one argument, which is a string. ... string values must be enclosed in quotes. ... The Run method will execute on c:\notepad.exe. ... I'm just learning vbscript for wsh and here is my first script, ...
    (microsoft.public.scripting.vbscript)