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

<anyone plss write full working code as per my requirement.i need it urgently.thogh i'm going through docs of perl to learn some basic. the code should work on this type of data data -- <script type="main> </script> <script> </script>

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

Replies are listed 'Best First'.
Re^7: perl script to search and replace comment in .aspx file
by Corion (Patriarch) on Jun 08, 2012 at 12:17 UTC
    No. This is not a code writing service. If it is so urgent for you, consider hiring somebody. We will assist you in learning Perl, and we have already shown you the parts that are needed for a program that will do what you seem to want. But combining these parts and finding the errors is the thing you need to do yourself.
Re^7: perl script to search and replace comment in .aspx file
by temporal (Pilgrim) on Jun 08, 2012 at 12:52 UTC

    I didn't know about YAPE. Nifty module. Thanks Corion, always seem to stumble into something new from reading your posts =)

    hector89, be sure to take some time to understand the code in all these replies it will help you write your own solution next time!

    This should do what you want:

    use strict; open my $input_fh, '<', 'your_input.aspx'; my $delim = $/; $/ = ''; my $file = <$input_fh>; $/ = $delim; close $input_fh; $file =~ s/(<%--)?\s*<script(.*?)>/($1 ? '' : "\n<%-- ") . "<script$2> +"/ige; $file =~ s=</script>\s*(-->)?='</script>' . ($1 ? '' : " -->\n")=ige; print $file; open my $output_fh, '>', 'your_output.aspx'; print $output_fh $file; close $output_fh;

    Forgot to turn off greedy matching for the script attributes group in my first post, which might be why you were having issues with input that's all on one line.

    Strange things are afoot at the Circle-K.

      thanx temporal for you support and helping me out..but still this code is not solving my purpose.this code does not work on this type of data: <script type=main ></script> and one more problem is this code replaces all things of file after modification. also this code is not able to uncomment the commented part.

        Oops. You will need to undef the input record seperator otherwise you will stop reading the file at the first blank line. Silly me.

        Works for me for all cases, including the one you posted =)

        Anyway, I think we can all agree that you have more than enough info on this node to be able to put together the code you're looking for. Good luck!

        Strange things are afoot at the Circle-K.