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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:53:58+00:00 2026-05-24T07:53:58+00:00

I am having a problem in the program code as I have changed my

  • 0

I am having a problem in the program code as I have changed my file into an array but not sure whether it has been changed or not. So please check the code given below also it is showing an error of use of uninitialized @data in last line.

Now after this, my biggest problem is that I want to collect only those elements within an array which have a specific keyword in between them. For example, each array’s element starts from where women ends and children begins. These words are common in all the other elements but information in between them are different and I want only those elements which has a keyword ‘factor man’ somewhere in between so I want to extract not all but only those elements which are having keyword ‘factor man’.

As you can see that my file is having all the initial words common in all the elements but after that the information is different but each element has a start from women and ends at children. please anyone could guide me regarding this.Thanks in advance.

Input file

women bds1
origin USA
accession not known
factor xyz
work abc
children
women sds2
origin ENG
accession known
factor man
work wwe
children
women cfc4
origin UK
factor xxx
work efg
children
women gtg6
origin UAE
factor man
work qqq
children

script

#!/usr/bin/env perl
use strict;
use warnings;

my $ifh;
my $line = '';
my @data;

my $ifn  = "fac.txt";

open ($ifh, "<$ifn") || die "can't open $ifn";
my $a = "women  ";
my $b = "children ";
my $_ = " ";
while ($line = <$ifh>)
{
chomp 
   if ($line =~ m/$a/g); {
     $line = $_;

   push @data, $line;

while ($line = <$ifh>) 
{
    $line .= $_;

push @data, $line;

last if 
($line =~ m/$b/g);
}

}

push @data, $line; }


print @data;

output

women  sds2
origin  ENG
accession known
factor  man
work  wwe
children
women  gtg6
origin  UAE
factor  man
work  qqq
children
  • 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-05-24T07:53:59+00:00Added an answer on May 24, 2026 at 7:53 am
    #!/usr/bin/perl
    use strict;
    use warnings;
    
    my @AoH;#Array of hashes
    my $ifn  = 'fac.txt';
    
    open my $fh, '<', $ifn or die "Failed to open $ifn: $!";
    
    my $i = 0;
    while(<$fh>){
        chomp;
        my @flds = split;
        $AoH[$i]{$flds[0]}{content} = $flds[1];
        $AoH[$i]{$flds[0]}{seqnum} = $.;
        $i++ if $flds[0] eq 'children';
    }
    
    foreach my $href (@AoH){
        if (${$href}{factor}{content} eq 'man'){
            foreach my $k (sort {${$href}{$a}{seqnum}
                            <=> ${$href}{$b}{seqnum}} keys %$href){
                my $v;
                if (defined ${$href}{$k}{content}){
                    $v = ${$href}{$k}{content};
                }
                else{
                    $v = ' ';#Space if undefined
                }
                print "$k $v\n";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having this problem wherein my threads stop execution and go into
I'm having problem when running my Windows Forms program. In the program, I have
all. I'm having a bit of weird problem with client server program. I have
I'm having a problem that I have encountered before, but I still don't know
I am having a strange problem in my code. I have many asserts scattered
Im having a problem dynamically loading beans in my program. I have my facelet
I have been trying to add a .cu file into my own(dll) win32 project
I'm having a problem converting my program from VS2005 to VS2008. When I run
I have a C++ program that will read in data from a binary file
Originally, I was having some issues getting this code to function, but after a

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.