• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert perl to java

 
Carneige Roder
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help to convert this code to java:
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carneige,
What do you have so far in Java?
 
Carneige Roder
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nothing so far. Idon't know where to begin.
any ideas?
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carneige Roder:
nothing so far. Idon't know where to begin.
any ideas?


It looks pretty straightforward, the perl code doesn't seem to be doing anything fancy. (and for perl, that is hard to do -- it is a really feature rich language)

The first two lines open files, one for reading, one for writing. The while, if, elsif (else if), and eq (string comparison) maps to a java counterpart. The print just maps to a print outputstream counterpart. You may need to wrap it in a print output stream.

The funny statement in the while, is read a line and make sure it is not null.

The first line in the while loop is the one problem. It basically say send $line to a regular expression and put the values in $1, $2, etc., which are assigned to variables in the next few lines. Unfortunately, you need to understand regular expressions to do this.

Anyway, I just converted the perl code to a design outline. You get to write the Java code...

Henry
[ December 04, 2004: Message edited by: Henry Wong ]
 
Carneige Roder
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but didn't help me much
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carneige Roder:
Thanks but didn't help me much


I completely broke down the perl program for you... unless you don't know Java, you definitely have enough to begin. Just get started, it isn't that hard.

Henry
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need some background on where you are having trouble. Have you ever programmed in Java? Have you ever programmed in Perl? Have you ever programmed at all? Henry's answer assumed you knew Java but were unfamiliar with Perl. If that's not the case, please give us a clue what your background is. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic