Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

To do this properly is difficult. As a start you need to do somthing like this:

local $/; # undef $/ so we glob data in $data = <DATA>; # get all our data as a string $data =~ s|//.*\n|\n|g; # strip single line comments $data =~ s|/\*.*?\*/||gs; # strip multi-line comments $data =~ s|^\s*\n||gm; # strip blank lines $data =~ s|^\s+||gm; # strip leading whitespace $data =~ s|\s+$||gm; # strip trailing whitespace # do the magic and split into functions @functions = split /(?=\bfunction\s)/, $data; # pudding proof print "$_ ---\n" for @functions; __DATA__ var answer = 42; // just because function 1 { blah // comment; } /* this function is no good function 2 { blah } */ function 3 { if (functionvar){ // var name not function keyword // do the blah stuff } } /* this is another comment */ function 4 { just another perl hacker }

You need to remove all the comments first to ensure that the only occurences of the word function represent keywords. You can then just use split with a positive lookahead assertion in the regex to generate your array. The next step you want to do is much harder but that is another story.




In reply to Re: Compressing/Obfuscating a Javascript file by tachyon
in thread Compressing/Obfuscating a Javascript file by Incognito

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (6)
    As of 2020-04-05 01:52 GMT
    Find Nodes?
      Voting Booth?
      The most amusing oxymoron is:

      Results (33 votes). Check out past polls.