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>


Reply via email to