Perl keeps me from throwing up while programming java

B

Bryan Castillo

use strict;
use warnings;
use Tk;

my $top = MainWindow->new();
my $t1 = $top->Scrolled(
'Text', -scrollbars=>'se',
-height=>5, -width=>40, -wrap=>'none'
)->grid(
-row=>0,-col=>0,-sticky=>'nsew'
);
my $t2 = $top->Scrolled(
'Text', -scrollbars=>'se',
-height=>5, -width=>40, -wrap=>'none'
)->grid(
-row=>1,-col=>0,-sticky=>'nsew'
);
my $btn = $top->Button(-text=>'Generate (Java Crap)',
-command=>[\&generate, $t1, $t2])
->grid(
-row=>2,-col=>0,-sticky=>'e'
);

$top->gridRowconfigure(0, -weight=>1);
$top->gridRowconfigure(1, -weight=>1);
$top->gridRowconfigure(2, -weight=>0);
$top->gridColumnconfigure(0, -weight=>1);

MainLoop;

# generate getters and setters for those !@*&*n beans!
sub generate {
my ($t1, $t2) = @_;
my $text = $t1->get("0.0", "end");
my @lines = split /[\r\n]+/, $text;
my $out = '';
foreach my $line (@lines) {
if ($line =~ /
(\w+)\s* # variable type
(\[[\d\s]*\])?\s* # array type?
(\w+)\s* # variable name
(\[[\d\s]*\])?\s* # array type?
[;=]/x)
{
my ($type, $var) = ($1,$3);
my $array = $2 || $4;
$type .= " []" if ($array)
my $var_uc = ucfirst($var);
$out .= sprintf
" public %s get%s {\n return this.%s;\n }\n",
$type, $var_uc, $var;
$out .= sprintf
" public void set%s(%s %s) {\n this.%s = %s;\n }\n\n",
$var_uc, $type, $var, $var, $var;

}
}
$t2->delete("0.0", "end");
$t2->insert('end', $out);
}

# thats all I really had to say
 
A

A. Sinan Unur

(e-mail address removed) (Bryan Castillo) wrote in
Subject: Perl keeps me from throwing up while programming java
From: (e-mail address removed) (Bryan Castillo)
Newsgroups: comp.lang.perl.misc ....

$type .= " []" if ($array)

FYI, you are missing a semicolon at the end of this line.

Very cute, by the way.

Sinan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top