Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8490073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:00:27+00:00 2026-06-10T22:00:27+00:00

Hi I have a html called 1.html file like this <div class=t_l></div> <some> lines

  • 0

Hi I have a html called 1.html file like this

<div class="t_l"></div>
 <some> 
   lines
     of
 codes
 </some>
<div class="t_r"></div>

I want to replace the content of that div to another one, which stored in the file called “banner”.
banner file is

<other> 
   lines
     of some
 codes
</other>

So what I want to get is:

<div class="t_l"></div>
 <other> 
   lines
     of some
 codes
 </other>
<div class="t_r"></div>

What I come up with using perl is something like this:

# Slurp file 1.html into a single string
open(FILE,"1.html") or die "Can't open file: $!";
undef $/;
my $file = <FILE>;
open(BANNER,"banner") or die "Can't open file: $!";
undef $/;
my $banner = <BANNER>;
close BANNER;

# Set strings to find and insert
my $first_line = '<div class="t_l"></div>';
my $second_line = '<div class="t_r"></div>';

$file =~ s/$first_line\n.+?\n$second_line#s/$first_line\n$banner\n$second_line/;

close FILE;

# Write output to output.txt
open(OUTPUT,">1new.html") or die "Can't open file: $!";
print OUTPUT $file;
close OUTPUT;

The above code cannot work. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:00:29+00:00Added an answer on June 10, 2026 at 10:00 pm

    You’re almost there.

    The normal regex behavior of . is to match any character except a newline. .+? in your regex doesn’t work for you because there are more newline characters between $first_line and $second_line.

    Using the /s modifier tells Perl to let . match newline characters, too.

    (You also have an extraneous “#s” in your expression)

    So a working substitution is:

    $file =~ s/$first_line\n.+?\n$second_line/$first_line\n$banner\n$second_line/s;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file called proof.html like this one: <title>{title}</title> <link rel=stylesheet type=text/css href={cssURL}
So I have a file called WebParts.aspx which looks like this - <%@ Page
I have an index.html file which looks like this (the rest is omitted), <ul
I have a form that I want to validate looks like this: <!DOCTYPE html
I have a view like this: <div id=basic-information-container> @Html.Action(MyBasicInformation) </div> <div id=cv-container> @Html.Action(MyCv) </div>
I have a script called at the end of an html page like this.
I have this two lines of html code... <div id=slider1 data-param1=XXX data-param2=XXX></div> <script src=script.js
I have an html file called snake.html that I would like to put inside
I have a file called header.html and it is included by base.html . In
I have a file called 34.php?session=2534464a39a2c97cb7113689726a4e52 in my /var/www/html folder but I can't view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.