#!/usr/bin/perl
while(<STDIN>){
$funcname = '';
if(/^([hide|show]+)Field\(([a-zA-Z]+)\(\)\)/){
$type = $1;
@functionnames = split(/([A-Z])/, $2);
foreach $func (@functionnames){
if ($func =~ /[A-Z]/){
$func = '_' . lc($func);
}
$funcname .= $func;
}
print "\$('#" . $funcname . "')." . $type. "\n";
} else {
print;
}
}
[hornet]$ perl test.pl < test.js
test js
$('#field_name').hide
$('#field_name').show
$('#_stan_this').show
hidefield(stanThat())
[hornet]$ cat test.js
test js
hideField(fieldName())
showField(fieldName())
showField(StanThis())
hidefield(stanThat())
Stan
On Tue, Apr 28, 2009 at 6:10 PM, AJ ONeal <[email protected]> wrote:
> I've got a 7k-line javascript file that I'm trying to make readable and
> drastically reduce the size of.
>
> Essentially I have several hundred lines like
> hideField(fieldName())
>
> which I would like to turn into
> $('#field_name').hide()
>
> and then I could delete several hundred lines of these hideField,
> showField, fieldAName(), fieldBName(), etc functions which are essentially
> just wasting space and overcomplicating the code.
>
> I don't have enough regex-fu under my belt to have any reasonable idea of
> how to do this.
> Could any of you offer me some suggestions?
>
> AJ ONeal
>