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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:34:46+00:00 2026-06-07T03:34:46+00:00

I’d like to write a short Perl prg that has 1 parameter (a 3

  • 0

I’d like to write a short Perl prg that has 1 parameter (a 3 digit integer) passed to it, and depending which list it’s a member of it returns the corresponding list’s number. How can I achieve this, also is there any way to put a range of number as an element in a list ?

 ::Returns 1,2,3,4 Depending on testNum passed
 @gp1= (829,845,851,859,864,867);
 @gp2= ("826-828","830-839","843-844","847-850","852-854","860-862","883");
 @gp3= ("855-858",861,"863","865");
 @gp4= ("877-882",884);

 if ( ($ARGV[0]>=822 && $ARGV[0] <=824) || $ARGV[0]  is membergp1)
 {  
  return 1
 }
  if ( $ARGV[0]>=826 && $ARGV[0]<=828 || $ARGV[0] is memebr of group2
    return 2
  if $ARGV[0] is memebr of group3
      return 3
  if $ARGV[0] is memebr of group4
      return 4
  • 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-07T03:34:48+00:00Added an answer on June 7, 2026 at 3:34 am

    Three-digit numbers require an array of only one thousand elements. I suggest unpacking the data into an array and simply indexing that array with the passed parameter.

    This program shows the idea. It expects the three-digit number on the command line.

    use strict;
    use warnings;
    
    my @gp1=  qw(  829  845  851  859  864  867  );
    my @gp2=  qw(  826-828  830-839  843-844  847-850  852-854  860-862  883  );
    my @gp3=  qw(  855-858  861  863  865  );
    my @gp4=  qw(  877-882  884  );
    
    my @places;
    
    my $n = 0;
    for (\(@gp1, @gp2, @gp3, @gp4)) {
      $n++;
      for (@$_) {
        my @indices = /\d+/g;
        $places[$_] = $n for $indices[0] .. $indices[-1];
      }
    }
    
    my $val = $ARGV[0];
    my $place = $places[$val];
    printf "Value %s appears in %s\n", $val, $place ? "group $place" : "no group";
    

    output

    Value 832 appears in group 2
    

    Update

    Alternatively you could check whether the passed parameter matches each range as you process it.

    The output is identical to the previous solution.

    use strict;
    use warnings;
    
    my @gp1=  qw(  829  845  851  859  864  867  );
    my @gp2=  qw(  826-828  830-839  843-844  847-850  852-854  860-862  883  );
    my @gp3=  qw(  855-858  861  863  865  );
    my @gp4=  qw(  877-882  884  );
    
    my $val = $ARGV[0];
    
    my $n = 0;
    for (\(@gp1, @gp2, @gp3, @gp4)) {
      $n++;
      for (@$_) {
        my @indices = /\d+/g;
        if ($val >= $indices[0] and $val <= $indices[-1]) {
          printf "Value %s appears in group %d\n", $val, $n;
          exit;
        }
      }
    }
    
    printf "Value %s appears in no group\n", $val;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I used javascript for loading a picture on my website depending on which small
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.