Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'throw perl to swine' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
throw perl to swine
Authored by: code_monkey on Aug 06, '02 03:14:46PM

Same kind'a thing but with file input/output:

#!/usr/bin/perl -w
use strict;

if(($#ARGV) != 1)
{
print "Need java file and output file names/paths; i.e. foo.pl /home/monkey/bar.java /home/monkey/foo.log\n";
die;
}

my $java_file = $ARGV[0]; #the filename and path of the file containing the data tobe imported.
my $report_file = $ARGV[1]; #filename and path of the report file.

open (FILEHANDLE, "<$java_file") || die $!;
while (<FILEHANDLE>)
{
my $inline = $_;
if($inline =~/^\s*(private|public)\s+(?:\s*static\s*|\s*final\s*|\s*transient\s*)*\s*(\w+)\s+(\w+)\s*[\;|\=]/)
{
add_to_file($1,$2,$3);
}
}
close(FILEHANDLE);

sub add_to_file
{
my ($scope, $type, $var) = @_;
my $name = ucfirst($var);
open (FH, ">>$report_file") || die $!;
print FH "\npublic $type get$name()";
print FH "\n{";
print FH "\n return $var;";
print FH "\n}\n";
print FH "\npublic void set$name($type val)";
print FH "\n{";
print FH "\n $var = val;";
print FH "\n}\n";
close(FH);
}

prolly loads of cases i've missed in that regex; but hey, half the fun is filling in the blanks ;)



[ Reply to This | # ]