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

The Archive Base Latest Questions

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

Possible Duplicate: How to join two substrings in perl How could I find a

  • 0

Possible Duplicate:
How to join two substrings in perl

How could I find a substring of a string array which corresponds to user entered index of character?

For example: If there is a string $string = 'MFHYRAKCLAMSCTLPHCAKNDHGCTH';and it get broken into array @string = ( "MFHYRA","KCLAM", "SCTLP", "HCAKNDHGCTH" ) ; now if user enters position of A as 6 and 10, how could two corresponding substrings be searched and joined?

  • 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-13T01:10:22+00:00Added an answer on June 13, 2026 at 1:10 am

    Essentially, what you ask is this: we have a position in the initial string. The string gets split up in substrings. In which of the substrings is the position?

    Assume that

    @pos = ( 5, 7, 9 ) ;
    

    is the list of positions for which you would like to find the substrings.

    my $n = 0 ; # current position
    
    my %results ;
    foreach my $ss ( @substrings ) {
    
      $n += length( $ss ) ;
    
      foreach my $p ( @pos ) {
        if( ! $results{$p} and $p < $n ) { $results{$p} = $ss ; }
      }
    
    }
    
    foreach my $p ( @pos ) {
      print "Position $p, substring $results{$p}\n" ;
    }
    

    Clearly, this code could use some optimalization, for example — no need to loop over the elements of @pos if we already have a substring for them, and we should break the operation after the last element of @pos got its substring, but for a few positions entered for the user this doesn’t really matter.

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

Sidebar

Related Questions

Possible Duplicate: Why is string concatenation faster than array join? Usually we need to
Possible Duplicate: What is the LINQ way to implode/join a string array? Say I
Possible Duplicate: How do I join two lines in vi? I have the following
Possible Duplicate: array join() method without a separator I'm using .join() to convert my
Possible Duplicate: SQL JOIN: is there a difference between USING, ON or WHERE? Which
Possible Duplicate: Inner join vs Where Hello in many interviews they ask which is
Possible Duplicate: How to join two tables table 1 Date StartingAum 07/01/2010 120 08/01/2010
Possible Duplicate: how to join 2 tables I am very new to databases. I
Possible Duplicate: How to join data frames in R (inner, outer, left, right)? This
Possible Duplicate: What is the difference between Join and Union? How do we combine

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.