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 On 3/23/06, Timothy Johnson <[EMAIL PROTECTED]> wrote: > > At first glance it looks like this should work: > > $fcode =~ s/^\s*function\s+(?:\w+\(\)\s*)?\s*\{\s*\n//gi; > > but I don't have any code to test it on. What do you expect to happen, > and what is really happening? > > -----Original Message----- > From: Kevin Old [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 23, 2006 11:17 AM > To: Perl Beginners > Subject: Javascript Regex to Perl Regex > > Hello everyone, > > I have a piece of javascript that formats a chunk of javascript into a > "pretty print" version of it. I'd like to have a command line version > of this, but can't seem to get the regexes to work in Perl. Just a > long shot, but can anyone help with the conversion of them from JS to > Perl? > > Here's the code: > > <html> > <body> > > <script type="text/javascript"> > function prettyScript(code) { > try { > var fcode = (new Function(code)).toString(); > fcode = fcode.replace(/^\s*function\s+(?:\w+\(\)\s*)?\s*\{\s*\n/, > ""); > fcode = fcode.replace(/\s*}\s*$/, ""); > return fcode; > } catch (e) { > return "SYNTAX ERROR: " + e.message; > } > } > </script> > <form action="" > onsubmit="this.elements.output.value = > prettyScript(this.elements.input.value); > return false;"> > <textarea id="input" cols="80" rows="5">"code to format > here"</textarea><br> > <input type="submit" value="format"><br> > <textarea name="output" cols="80" rows="10" readonly="readonly">Output > here</textarea><br> > </form> > > </body> > </html> > > Any help is appreciated, > Kevin > -- > Kevin Old > [EMAIL PROTECTED] > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>