File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes convert perl to java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "convert perl to java" Watch "convert perl to java" New topic
Author

convert perl to java

Carneige Roder
Greenhorn

Joined: Nov 09, 2004
Posts: 5
I need help to convert this code to java:
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31085
    
163

Carneige,
What do you have so far in Java?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Carneige Roder
Greenhorn

Joined: Nov 09, 2004
Posts: 5
nothing so far. Idon't know where to begin.
any ideas?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19074
    
  40

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 ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Carneige Roder
Greenhorn

Joined: Nov 09, 2004
Posts: 5
Thanks but didn't help me much
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19074
    
  40

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

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert perl to java