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

  • SEARCH
  • Home
  • 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 8536263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:37:19+00:00 2026-06-11T10:37:19+00:00

My code tries to extract the range even if the line starts with a

  • 0

My code tries to extract the range even if the line starts with a * Here is my code:

while (<FILE1>) {

    $_ =~ s/^\s+//; #remove leading spaces
    $_ =~ s/\s+$//; #remove trailing spaces

    if (/IF/ .. /END-IF/) {

        if($_ =~ m/END-IF/) {

            $flag = 1;
        }
        print FINAL "$_\n";

        if ($flag == 1) {

            $flag = 0;
            print FINAL "\n\n";
        }
    }
}
close FINAL;
close FILE1;

My FINAL output file should contain only the the ranges between all IF’s and END-IF’s seperated by \n\n AND if there is an IF within an IF block, The range starting from the first if to the line before the second IF should be saved in FINAL seperated by \n\n

  • 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-11T10:37:20+00:00Added an answer on June 11, 2026 at 10:37 am

    if you want IF and END-IF to be excluded,then use the below:

    perl -lne 'if(/IF/.../END-IF/ and $_!~/^\*|IF|END-IF/){print}' your_file
    

    if you want IF and END-IF to be included,then use the below:

    perl -lne 'if(/IF/.../END-IF/ and $_!~/^\*/){print}' your_file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code utilizes CreateProcess to run commands with environmental variables. Here, it tries
Based on code suggestions here at stackoverflow, I've tried to extract an image from
My code tries to extract a filename to load a file from reading another
The following code tries to attach to an excel session that has the C:\test
I try to draw some lines with different colors. This code tries to draw
The code below tries to parse a file containing these 3 lines: 0 2
i have this hap code of which tries to selects sub-node from the main
I tries to delete an entity - table This is the code: db.Sessions.SqlQuery(delete table
I tried this code to open a file in Python: f = open("/Desktop/temp/myfile.txt","file1") It
Current Code: WHERE EXTRACT(YEAR_MONTH FROM timestamp_field) = EXTRACT(YEAR_MONTH FROM now())) Instead of EXTRACT(YEAR_MONTH FROM

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.