On 3/23/06, Kevin Old <[EMAIL PROTECTED]> wrote: > Here's what I have. > > # Open js file > open JSFILE, "$ARGV[0]" or die "can't open file: $ARGV[0]"; > my $js = do { local( $/ ); <JSFILE> }; > close JSFILE; > > # Clean js > $js =~ s/^\s*function\s+(?:\w+\(\)\s*)?\s*\{\s*\n//gi; > $js =~ s/\s*}\s*$//gi; > > # Write new js file > open JSOUTFILE, ">out_$ARGV[0]" or die "can't open file: out_$ARGV[0]"; > print JSOUTFILE $js; > close JSOUTFILE; > > If you cut and past the HTML and run it in a browser it will turn code > like this: > > function wR(_1,_2,_3,_4){ > var _5=document.getElementById("w"+_1); > var _4=_4||window.event; > sbHandler.prediction=_3; > RatingManager.handleMouseover(_4,_5); > } > > into this: > > function wR(_1, _2, _3, _4) { > var _5 = document.getElementById("w" + _1); > var _4 = _4 || window.event; > sbHandler.prediction = _3; > RatingManager.handleMouseover(_4, _5); > } > > I'm trying to at least duplicate that, and add a few other > improvements. When I run my script it's not changing anything. > > Any suggestions? > > Kevin
You'll have to explain your js a little. At first glance, your javascript code would seem to replace your entire first and last lines with the null string. Based on the output you present, though, your code will depend a great deal on the complexity you want from your output. The main features of your example, as I see them: * You indent every line a few spaces. * Yout indent lines that don't begin with 'function' or '}' a few more lines. So something like this: open OUT, ">" $your_out_file; while (<>) { if ( s/^\s*((?:function)|(?:\}))/ $1/i ) { print OUT $_; next; } else { s/^\s*/ /; print OUT $_; } close(OUT); If you have something that works, though, and you're using it other places and want to keep everything synchronized, check out the Javascript module from CPAN; HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!