in reply to Re: perl script to search and replace comment in .aspx file
in thread perl script to search and replace comment in .aspx file

but if my script structure is like this: <script type="java/js"> </script>,then its not working..any solution

  • Comment on Re^2: perl script to search and replace comment in .aspx file

Replies are listed 'Best First'.
Re^3: perl script to search and replace comment in .aspx file
by stevieb (Canon) on Jun 07, 2012 at 18:19 UTC
Re^3: perl script to search and replace comment in .aspx file
by aaron_baugher (Curate) on Jun 07, 2012 at 19:01 UTC

    Any time you're parsing text, a lot depends on how much the patterns you're trying to match may vary. If your tags may or may not span multiple lines, or may have their attributes in different orders, or other variations, parsing them can be very complicated. (Which is why it's often a good idea to use a module if there is one.) If you know your open and close tags will always be on the same line, and never more than one pair on the same line, it could be pretty simple:

    perl -p -i -e 's|(<script.+/script>)|<%-- $1 -->| unless s|<%--(\s*<sc +ript.+/script>\s*)-->|$1|' *.aspx

    Aaron B.
    Available for small or large Perl jobs; see my home node.