How to pass string in command line argument.
6 answers - 1268 bytes -

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 ERRR";
} 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
No.1 | | 1455 bytes |
| 
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 ERRR";
} 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")
Why are you shelling out to another Perl process just to print a value from a
hash? As far as I can tell your loop should look like this:
foreach my $item (@{$ref->{reff}}) {
print qq("$item->{var2}"\n);
}
Cheers,
Rob
No.2 | | 2608 bytes |
| 
perl pra wrote:
>
Rob Dixon wrote:
>>
>perl pra wrote:
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 ERRR";
} 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")
>>
>Why are you shelling out to another Perl process just to print a value
>from a
>hash? As far as I can tell your loop should look like this:
>>
>foreach my $item (@{$ref->{reff}}) {
>print qq("$item->{var2}"\n);
>}
>
thats just example i gave actually i have to search for the
string with quote included in the string.
>
I am clueless abt the solution as i am beginner.
>
waiting for some suggestion or solution.
(Please keep your posts on the beginners list so that others can help me to help
you, and also benefit from the solution to your problem. Thanks.)
Please tell us exactly what it is you need to do. Shelling into Perl from
Perl is almost certainly the wrong way to go about it, but It's not at all clear
what end result you need.
What I can suggest is this:
perl -e "print $ARGV[0], qq(\n)" "\"xxx\""
but I have the horrible feeling I'm helping you to create something very ugly!
Let us know the full details please,
Rob
No.3 | | 1779 bytes |
| 
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 ERRR";
} 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} . '"');
, 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.
No.4 | | 3338 bytes |
| 
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 R)
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
10/26/06, Mumia W. <mumia.w.18.spam+nospam (AT) earthlink (DOT) netwrote:
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 ERRR";
} 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} . '"');
, 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.
>
>
>
No.5 | | 6320 bytes |
| 
perl pra wrote:
>
10/26/06, Mumia W. <mumia.w.18.spam+nospam (AT) earthlink (DOT) netwrote:
>>
>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 ERRR";
>>
>} 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} . '"');
>>
>, 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 R)
>
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
No.6 | | 4908 bytes |
| 
10/28/2006 01:52 AM, perl pra wrote:
10/26/06, Mumia W. <mumia.w.18.spam+nospam (AT) earthlink (DOT) netwrote:
>>
>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 ERRR";
>>
>} 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} . '"');
>>
>, 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 R)
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 .)
Did you see the double backslashes I had in my program?
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
--
Perl Pra, please bottom-post your replies. When you reply, place your
reply below the quoted text. This makes technical conversations more
logical.
my Linux system, this program prints "Hi there" :
if (@ARGV < 1) {
system (qq{$0 "\\"Hi there\\""});
} else {
print $_, "\n" for (@ARGV);
}