We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

passing perl variable to an external command

areyouready344
on
Medium Priority
288 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

Comment
Watch Question

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
sorry I meant without backticks of course:

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

Commented:
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

Author

Commented:
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

Author

Commented:
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
Top Expert 2009

Commented:
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";

Commented:
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";

Top Expert 2009

Commented:
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.

Author

Commented:
thanks mostart and adam314, all is working....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.