hii, i have written a code to comment out certail lines in a file based on some condition. i want to apply comment and uncomment thing on this type of data: data -------

<%--JS one Link Start <script main="js src="js/libs/"></script> <%--JS one Link End <%--JS second Link Start--%> <script main="js/scripts Main" src="js/libs"></script> <%--JS second Link End--%>
--------------------------------------- in this data if "one Link Start" is found without "--%>" and "second Link Start" is found with "--%>" character then trim "--%>" from "second Link Start" and append to "one Link Start" and vice versa. i have tried this code but not working. thanks in advance if anyone help me here.

#!/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 =~ /\s+.* one Link Start$/){ next unless($line=~/\s+.*second Link Start\s*--%>$/); $line =~ s/\s+--%>//; s/\s+.* one Link Start$/\s+.* one Link Start\s*--%>/gi; } elsif ($line =~ /\s+.* second Link Start$/){ next unless($line=~/\s+.*oneLink Start\s*--%>$/); $line =~ s/\s+--%>//; s/\s+.* second Link Start$/\s+.* second Link Start\s*--%>/gi; } } close $fh; print $line; open(my $output_fh, '>', 'hii.txt') or die "Unable to open file for writing: $!"; print $output_fh $line; close $output_fh;

In reply to appending comment character in multiple lines based on condition by hector89

Title:
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, details, 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, summary, 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.