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

The Archive Base Latest Questions

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

I am trying to break a string at every occurrence of ‘E’. But in

  • 0

I am trying to break a string at every occurrence of ‘E’. But in output I want to skip those substrings which had arrived earlier in the previous loop of breakage. For eg. If I take a string $s='ABCDEABCDEABCDEABCD' where ‘E’ is present at 5th, 10th and 15th position in a string, substrings which appeared as the result of breakage at position 10 should not appear in the substrings resulting from the breakage at position 15. Script given below breaks at every position of ‘E’. But I’m unable to stop the substring repetitions. Please help!

my $s = 'ABCDEAXBCDEAYBCDEAZBCD';
my @where; my @array;my @final;
my $result; my $j; 

for ($j = 0; $j <= 2; $j++) {

    $where[j] = index($s,"E",$where[j-1]) + 1;
    push @array, $where[j];
}


for my $array (@array) {

    substr($s, $array-1, 1) = "\0";
    my @a = split(/E(?!P)/, $s);
    substr($s, $array-1, 1) = 'E';

    $_ =~ s/\0/E/g foreach (@a);
    $result = join ("E,", @a).'E'; 
    @final  = split(/,/, $result);
    print "@final\n";
}

Output which I’m getting is:

ABCDEAXBCDE AYBCDE AZBCDE
ABCDE AXBCDEAYBCDE AZBCDE
ABCDE AXBCDE AYBCDEAZBCDE

Expected Output:

ABCDEAXBCDE AYBCDE AZBCDE
ABCDE AXBCDEAYBCDE
AXBCDE AYBCDEAZBCDE
  • 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-13T15:35:34+00:00Added an answer on June 13, 2026 at 3:35 pm

    I don’t understand the purpose/description of your problem, but you can add a hash that keeps track of substrings you have seen previously and drop them, by changing the last loop to something like:

    my %seen;
    for my $array (@array) {
      substr($s, $array-1, 1) = "\0";
      my @a = split(/E(?!P)/, $s);
      substr($s, $array-1, 1) = 'E';
      $_ =~ s/\0/E/g foreach (@a);
      $result = join ("E,", @a).'E'; 
      @final = grep { !exists $seen{$_} } split(/,/, $result);
      $seen{$_}=1 for @final;
      print "@final\n";
    }
    

    That changes the output to:

    ABCDEAXBCDE AYBCDE AZBCDE
    ABCDE AXBCDEAYBCDE
    AXBCDE AYBCDEAZBCDE
    

    Your code looks like it has been translated from C. If you try to describe more clearly what it is you want to do, maybe someone can help your with a more idiomatic Perl version.

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

Sidebar

Related Questions

I am trying to calculate prime numbers, which I've already done. But I want
I'm trying to find a way to break a string at the second last
I have the vector output = PV_out(:); I am trying to break this down
I'm trying to match a string inside an HTML for example I want to
I am trying to break down the following string: @command Text1 @command2 Text2 in
I've been trying for over an hour to fix my makefile but I break
I am trying to break some of my old habits of writing bad code.
I'm really trying to break out of my RDBMS mind set when setting up
I am trying to break a huge SQL file into little sql file and
I am trying to break away from using tables in my formatting, and am

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.