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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:19:50+00:00 2026-06-05T20:19:50+00:00

Given the following input: A| 11 162 60 90 — 141 184 B| 231

  • 0

Given the following input:

A| 11 162 60 90 — 141 184

B| 231 322 — 306 305 285 350

For A, I want to check if 141 lies between (11,162) OR (60,90) inclusive.
If yes, print “In A, 141 lies between (11,162)”.

Then, I want to check if 184 lies between (11,162) OR (60,90) inclusive.
Since it doesn’t, nothing needs to be printed.

Similarly, for B, I need to print the numbers that lie between (231, 322).

I wrote the following Perl code but I am not getting the correct output.

#!/usr/bin/perl -w
open LIST, "input.txt";
while($line=<LIST>)
{
@elem=split (/\|/,$line);
@nextone=split("--",$elem[1]);
@nextoneone = split(" ",$nextone[0]);
@nexttwo=split(" ",$nextone[1]);

if ($nexttwo[0] > $nextoneone[0] && $nexttwo[0] < $nextoneone[1])
{
print"$elem[0]\t $nexttwo[0]\t $nextoneone[0]\t $nextoneone[1]\n";
}
elsif ($nexttwo[0] > $nextoneone[2] && $nexttwo[0] < $nextoneone[3])
{
print"$elem[0]\t $nexttwo[0]\t $nextoneone[2]\t $nextoneone[3]\n";
}
elsif ($nexttwo[1] > $nextoneone[0] && $nexttwo[1] < $nextoneone[1])
{
print"$elem[0]\t $nexttwo[1]\t $nextoneone[0] \t$nextoneone[1]\n";
}
elsif ($nexttwo[1] > $nextoneone[2] && $nexttwo[1] < $nextoneone[3])
{
print"$elem[0]\t $nexttwo[1]\t $nextoneone[2] \t$nextoneone[3]\n";
}
}
   close (LIST);
   exit;

I don’t know how many elements are there in each row. Therefore, I do not know how to implement a loop for comparison.
Any guidance on how to improve the code will be appreciated.

Thank you for your help.

  • 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-05T20:19:52+00:00Added an answer on June 5, 2026 at 8:19 pm

    Firstly, I would change a couple of things about your script.
    1) use strict – it’ll mean you catch any typos

    2) give variables more meaningful names – I’ve changed some that make sense based on what I saw, but I don’t know what your script does, so you may have better ones

    3) Output some debug, while you’re developing it, so you can see what it’s doing and why it’s not working

    You will need two loops – one to loop over the values in the part of the string to the left of ‘–‘ and one to loop over the conditions on the right side. You want to loop through the values in the outer loop and then each time through that you should loop through ALL the conditions in the inner loop.

        use strict;
        #!/usr/bin/perl -w
        open LIST, "input.txt";
        my $line;
        while($line=<LIST>) {
            my ($label, $content) =split (/\|/,$line);
            my ($conditionstring, $valuestring) =split("--",$content);
            my (@conditions) = split(" ",$conditionstring);
            my (@values) =split(" ",$valuestring);
            foreach my $this_val (@values) {
                    my $matched_one_condition = 0;
                    for (my  $f=0; $f< scalar(@conditions);$f+=2) {
    
    
                            print "Comparing $this_val to $conditions[$f] and to            $conditions[$f+1]\n";
    
                            if (($this_val > $conditions[$f]) && ($this_val < $conditions[$f+1])) {
                                    $matched_one_condition= 1;
    
                            }
                    }
                    if ($matched_one_condition) {
                            print "$this_val\n";
    
                    }
            }
    }
    

    Note – I’ve left the debug line in there

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code: $(.force-selection).blur(function() { var value = $('matched-item').val(); //check if the input's
Given the following input 506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,04/26/2012, I want to filter the date at the
Given the following input - I went to 1 ' and didn't see p
Given the following HTML and function: <input type=text onfocus=TextBoxFocus() id=txtName /> . function TextBoxFocus()
Given the following HTML form: <form id=myform> Company: <input type=text name=Company value=ACME, INC./> First
Given the following code: <form> <input type=text> <select> <option>Foobar</option> </select> </form> With the following
given following html <input id=IBE1_IBE_NurFlug1_RadioButtonList1_0 name=IBE1$IBE_NurFlug1$RadioButtonList1 value=Blue type=radio> <label for=IBE1_IBE_NurFlug1_RadioButtonList1_0>Blue</label> <input id=IBE1_IBE_NurFlug1_RadioButtonList1_1 name=IBE1$IBE_NurFlug1$RadioButtonList1 value=Green
Given the following HTML fragment: <span name=foo class=foo-class> <input name=foo value=0 id=foo2_0 type=radio> <label
Given the following code snippets, is there any appreciable difference? public boolean foo(int input)
Newbie question. Given the following html. <div id=mycontainer1 class=container> <input type=text class=name/> <input type=text

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.