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 7839617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:29:47+00:00 2026-06-02T15:29:47+00:00

I have a data like this: Re: Building A Month kWh 1 100 2

  • 0

I have a data like this:

Re: Building A

Month
kWh
1
100
2
110
3
105


Re: Building B

Month
kWh
1
200
2
210
3
205

I would like to convert it to multiple text files one for each building. My plan is to:

  1. extract the values between the building delimiter line
  2. convert the lines into a table

For task (1) I tried to use the flip-flop operator like this:

while( <DATA> ) {
  next unless /^Re: Building A/ .. /^Re: Building B/;
  my $line = $_;
  print $line;
}

But it does not work because the above will show only the data for building A. The data is for multiple buildings (about 50 of them) so that I need to do this somewhat recursively. I have not started to do task (2).

Any help will be appreciated.

  • 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-02T15:29:49+00:00Added an answer on June 2, 2026 at 3:29 pm

    I would do something like this:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    my %buildings;
    
    while (<DATA>) {
        chomp;
        $buildings{$1} = [] if /^Re: Building ([AB])/;
        push @{$buildings{$1}}, $_ if $_;
    }
    
    while (my ($building, $data) = each %buildings) {
        open(my $out, '>', "$building.txt") or die "Unable to open file for writing: $!\n";
    
        for my $i (1 .. $#$data / 2) {
            print $out sprintf "%s\t%s\n", $data->[$i*2-1], $data->[$i*2];
        }
        close $out;
    }
    

    A.txt:

    Month   kWh
    1       100
    2       110
    3       105
    

    B.txt:

    Month   kWh
    1       200
    2       210
    3       205
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data structure designed like this: employee . department . building .
I have data like this: Team | goal a | 5 b | 8
Say I have data like this: <option value=abc >Test - 123</option> <option value=def >Test
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have some data like this : 1 TC1 PASS 2 TC2 FAIL 3
I have some data like this: -1,2752 -1,4735 1 -0,5500 1,3287 2 -1,6293 -2,1460
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},
I have a data like this. Is there any way to smoothen my plot
I have data that looks like this: #info #info2 1:SRX004541 Submitter: UT-MGS, UT-MGS Study:
I have a JSON data like this: { hello: { first:firstvalue, second:secondvalue }, hello2:

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.