Dear Stan,

You are a monster.

Very nice!

Regards,

Flint

On Tue, 28 Apr 2009, Stanley Brinkerhoff wrote:

Date: Tue, 28 Apr 2009 18:36:23 -0400
From: Stanley Brinkerhoff <[email protected]>
Reply-To: Vermont Area Group of Unix Enthusiasts <[email protected]>
To: [email protected]
Subject: Re: batch replace camelCase with _underscores_?

#!/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



Kindest Regards,



Paul Flint
(802) 479-2360


/************************************
Based upon email reliability concerns,
please send an acknowledgment in response to this note.

Paul Flint
Barre Open Systems Institute
17 Averill Street
Barre, VT
05641

http://www.bosivt.org
http://www.flint.com/home
skype: flintinfotech
Work: (202) 537-0480

Consilium                                       _
gratuitum        .~.     ASCII ribbon campaign ( )
valet            /V\      against HTML e-mail   X
quanti          /( )\     www.asciiribbon.org  / \
numerantur      ^^-^^

Reply via email to