Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^7: perl script to search and replace comment in .aspx file

by temporal (Pilgrim)
on Jun 08, 2012 at 12:52 UTC ( #975158=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re^7: perl script to search and replace comment in .aspx file
Download Code
Re^8: perl script to search and replace comment in .aspx file
by hector89 (Novice) on Jun 08, 2012 at 13:59 UTC

    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.

        sorry i checked it for all cases but ity's true it's not working when it founds anyblankk line . so how to prevent that.really being first perl pro it seems tough to me but through help of you guys i started learning basics of perl.thanks.:)

        isolved the problem .now it rwead the blank line but new problem is if there is a spave between two wors in same line after first space itself it discards all like: <script type>..it only reading <script and discrds type>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://975158]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-07-25 05:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls