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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:21:35+00:00 2026-06-13T07:21:35+00:00

I open a text report inside my Perl script and need to find the

  • 0

I open a text report inside my Perl script and need to find the specific lines and store them in arrays.

this is my report which I need to process through:
matched pattern 1 
line1:10
line2:20
line3:30

next matched pattern 2
line1:5
line2:10
line3:15

next matched pattern 3
lineA:A
lineB:B
lineC:C
.
.
------------------------------------

this part is my script:

@numbers;
@numbers2;
@letters;
while (<FILE>)
{
 if ($_ =~/matched pattern 1/ && $_ ne "\n")
 {
   chomp();
   push (@numbers,$_)
 }
 if ($_ =~/next matched pattern 2/ && $_ ne "\n")
 {
   chomp();
   push (@numbers2,$_)
 }
 if ($_ =~/next matched pattern 3/ && $_ ne "\n")
 {
   chomp();
   push (@letters,$_)
 }
}

then I can use numbers and letters inside the arrays.
this is a part of my report file

Maximum points per Lab
Lab1:10
Lab2:30
Lab3:20


Maximum points per Exam
Exam1:50
Exam2:50

Maximum points on Final
Final:150
  • 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-13T07:21:37+00:00Added an answer on June 13, 2026 at 7:21 am

    What is your program supposed to be doing? Your current program is looking for the lines that have matched pattern and storing THOSE VERY LINEs into three different arrays. All other lines are ignored.

    You show some sort of example output, but there’s no real relationship between your output and input.

    First, learn about references, so you don’t need five different arrays. In my example, I use an array of arrays to store all of your separate files. If each file represents something else, you could use an array of hashes or a hash of arrays or a hash of hashes of arrays to represent this data in a unified structure. (Don’t get me started on how you really should learn object oriented Perl. Get the hang of references first).

    Also get a book on modern Perl and learn the new Perl syntax. It looks like your Perl reference is for Perl 4.0. Perl 5.0 has been out since 1994. There’s a big difference between Perl 4 and Perl 5 in the way syntax is done.

    use strict;
    use warnings;
    
    # Prints out your data strtucture
    use Data::Dumper;
    
    my $array_num;
    my @array_of_arrays;
    
    use constant  {
        PATTERN => qr/matched pattern/,
    };
    
    while (my $line = <DATA>) {
        chomp $line;
        next if $line =~ /^\s*$/;   #Skip blank lines
        if ($line =~ PATTERN) {
            if (not defined $array_num) {
                $array_num = 0;
            }
            else {
                $array_num++;
            }
            next;
        }
        push @{ $array_of_arrays[$array_num] }, $line;
    }
    print Dumper (\@array_of_arrays) . "\n";
    
    __DATA__
    matched pattern 1 
    line1:10
    line2:20
    line3:30
    
    next matched pattern 2
    line1:5
    line2:10
    line3:15
    
    next matched pattern 3
    lineA:A
    lineB:B
    lineC:C
    

    OUTPUT. Each set of lines are in a different array:

    $VAR1 = [
          [
            'line1:10',
            'line2:20',
            'line3:30'
          ],
          [
            'line1:5',
            'line2:10',
            'line3:15'
          ],
          [
            'lineA:A',
            'lineB:B',
            'lineC:C'
          ]
        ];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to open text files and load them into a RichTextBox. This has
I have a perl script creates a text file, writes captured lines from a
this is my code: f = open('text/a.log', 'wb') f.write('hahaha') f.close() and it is not
Is there any open source engine project which can classify online text or article.
I have a report in SQL Server Reporting Services which should show a text
I am trying to open a hyperlink with target=blank. <html> <head> <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js></script>
I have a build script where i create a text report file and output
I need my App to generate a report which can be emailed. It must
I need to generate a multi-page report document ultimately in pdf format which consists
I am trying to open a text file in python. In the following code:

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.