?
Solved

passing perl variable to an external command

Posted on 2009-02-13
9
Medium Priority
?
268 Views
Last Modified: 2012-05-06
Is this the right way to pass a perl variable to an extiernal command for wordnet?
use WordNet::QueryData;
my $wn = WordNet::QueryData->new;
 
my $dvalue;
print `$wn->querySense("$dvalue#n#7", "syns")), "\n"`;

Open in new window

0
Comment
Question by:areyouready344
  • 3
  • 3
  • 3
9 Comments
 
LVL 8

Accepted Solution

by:
mostart earned 2000 total points
ID: 23634311
you better code this way:

print `$wn->querySense(" . $dvalue . "#n#7", "syns")), "\n"`;

Check this link fpr more info and examples:
http://search.cpan.org/~jrennie/WordNet-QueryData-1.47/QueryData.pm
0
 
LVL 8

Expert Comment

by:mostart
ID: 23634331
sorry I meant without backticks of course:

print $wn->querySense(" . $dvalue . "#n#7", "syns")) . "\n";
0
 
LVL 39

Expert Comment

by:Adam314
ID: 23634543
Your quotes are not lined up.
You parenthesis are not lined up.
Also, double-quoted string will interpolate variables, so you don't need to explicitly use the . operator.
print $wn->querySense("$dvalue#n#7", "syns") . "\n";

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:areyouready344
ID: 23635220
Adam314, i tried your way but get the following error message

[root@localhost a-z]# perl output
syntax error at output line 21, near "print"
Global symbol "$dvalue" requires explicit package name at output line 21.
Missing right curly or square bracket at output line 36, within string
Execution of output aborted due to compilation errors.

line numbers below of code

     17 my $outputTotal = @output;
     18 my $dvalue = print "$output[$outputTotal - 10392","\n";
     19 #print "$dvalue", "\n";
     20 print $wn->querySense ("$dvalue#n#1","syns"),"\n";


What I'm doing wrong here?

many many thanks,
ARY
0
 

Author Comment

by:areyouready344
ID: 23635767
Can  anybody tell what might be the problem below?

[root@localhost a-z]# perl output
syntax error at output line 21, near "print"
Global symbol "$dvalue" requires explicit package name at output line 21.
Missing right curly or square bracket at output line 36, within string
Execution of output aborted due to compilation errors.

line numbers below of code

     17 my $outputTotal = @output;
     18 my $dvalue = print "$output[$outputTotal - 10392","\n";
     19 #print "$dvalue", "\n";
     20 print $wn->querySense ("$dvalue#n#1","syns"),"\n";


What I'm doing wrong here
0
 
LVL 39

Expert Comment

by:Adam314
ID: 23635797
I'm not sure what you are trying to do... but:

Line 17 will set $outputTotal to the number of elements in @output
    my $outputTotal = @output;

Line 18 has a syntax error.
    my $dvalue = print "$output[$outputTotal - 10392","\n";
I'm not sure what you were trying to do.  The return value from the print command is either true or false, indicating whether the print was successful.

Line 19 is a comment, and does nothing

Line 20 calls the querySense function of the $wn object, and prints the result.  There is no syntax error on this line.
    print $wn->querySense ("$dvalue#n#1","syns"),"\n";
0
 
LVL 8

Expert Comment

by:mostart
ID: 23636324
watch the "dot" before the "\n" in lines 18 and 20 should not be a comma.
Also line 18 looks strange to me (missing right square bracket).

   17 my $outputTotal = @output;
   18 my $dvalue = $output[$outputTotal] - 10392" . "\n";
   19 #print "$dvalue", "\n";
   20 print $wn->querySense ("$dvalue#n#1","syns") . "\n";

0
 
LVL 39

Expert Comment

by:Adam314
ID: 23636856
This isn't correct (line 18):
    my $dvalue = $output[$outputTotal] - 10392" . "\n";
There is a mismatch of double quotes, so it won't compile as is.

If you want $dvalue to be the last element of @output - 10392, you should do:
    my $dvalue = $output[-1] - 10392;

The original code had a print statement.  So I don't know what the trying to accomplish.
0
 

Author Comment

by:areyouready344
ID: 23637859
thanks mostart and adam314, all is working....
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question