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

You might tell us how the code fails for you, and on what input, and what output you get.

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

Replies are listed 'Best First'.
Re^4: perl script to search and replace comment in .aspx file
by hector89 (Novice) on Jun 08, 2012 at 06:15 UTC

    __DATA__ <script type="java/js"> foobie bletch </script> <%-- <script> zelgo mer </script> --> input is same as temporal used.but when i'm executing this code it's not able to make changes in file.i'm using .txt file

      temporal used the __DATA__ segment to avoid the need for an external file. You will need to learn how to open a file for reading and then read it in like temporal's code does. The code does not modify a file but it creates output that could be written to a new file. You will have to learn how to open a file for writing, too.

        As Corion stated, you need to learn how to open a file for both reading and writing. In this post I personally went as far as to write my code to give an example of each.

        i made some modification in reg exp in the code written by stevieb and it's working fine for this type of data data --- <script type="java/js"> foobie bletch </script> <%-- <script> zelgo mer </script> --> but problem is if i write endi script tag </script> not in the first column,it's not commenting or uncommenting that.

        #!/usr/bin/perl use warnings; use strict; open my $fh, '<', 'hii.txt' or die "Can't open the damn file for readi +ng!: $!"; my @file_content; while ( my $line = <$fh> ){ chomp $line; if ( $line =~ /^<script(.*)>/ ){ $line = "<%-- $line"; push @file_content, "$line\n"; next; } elsif ( $line =~ /^<\/script>$/ ){ $line .= " -->"; push @file_content, "$line\n"; next; } elsif ( $line =~ /^<%--\s+<script(.*)>/ ){ $line =~ s/^<%--\s+//; push @file_content, "$line\n"; next; } elsif ( $line =~ /^<\/script>\s+-->/ ){ $line =~ s/\s+-->//; push @file_content, "$line\n"; next; } push @file_content, "$line\n"; } close $fh; open $fh, '>', 'hii.txt' or die "Can't open the damned file for writin +g: $!"; print $fh @file_content; close $fh;
        <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>