Monday, May 24, 2010

How to embed java code in a perl script?

I am trying to embed Java code in a perl script using the Inline .


But when i run the script no output is shown . It seems that the script is hung since I don't even get back the command prompt.





#!/usr/bin/perl


use strict; use warnings;





use Inline Java =%26gt; %26lt;%26lt;'EOJ';


public class Hi {





String greeting;





public Hi(String greeting) {


this.greeting = greeting;


}





public void setGreeting(String newGreeting) {


greeting = newGreeting;


}





public String getGreeting() {


return greeting;


}


}


EOJ





my $greeter = Hi-%26gt;new("howdy");


print $greeter-%26gt;getGreeting(), "\n";

How to embed java code in a perl script?
I ran the above script in my Linux terminal, and it said there's an error on line 21. Line 21 is the line that said EOJ





Besides in Perl they have different commands.


for warnings, use -w [space -w] at the end of this line:


#!/usr/bin/perl


like this:


#!/usr/bin/perl -w


you cannot use the following comment:


use strict; use warnings


because the word "use" is a specific command in Perl scripting.





The perl interpreter doesn't know how to handle this, so it will definitely omit it.





I've used the warning


#!/usr/bin/perl -w


but there's still an error on Line 21 [Line that says "EOJ"]





Perl = Programming language


perl = language interpreter





No matter what I tried it will say


Can't locate Inline.pm [I don't have this installed] and there's an error on Line 20/21 [EOJ Line]





Sorry.
Reply:Add some print statements before %26amp; after the Hi-%26gt;new call, to find out where it's hanging...


No comments:

Post a Comment