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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:07:10+00:00 2026-06-09T19:07:10+00:00

Yesterday, I got stuck in a perl script. Let me simplify it, suppose there

  • 0

Yesterday, I got stuck in a perl script. Let me simplify it, suppose there is a string (say ABCDEABCDEABCDEPABCDEABCDEPABCDEABCD), first I’ve to break it at every position where “E” comes, and secondly, break it specifically where the user wants to be at. But, the condition is, program should not cut at those sites where E is followed by P. For example there are 6 Es in this sequence, so one should get 7 fragments, but as 2 Es are followed by P one will get 5 only fragments in the output.

I need help regarding the second case. Suppose user doesn’t wants to cut this sequence at, say 5th and 10th positions of E in the sequence, then what should be the corresponding script to let program skip these two sites only? My script for first case is:

my $otext = 'ABCDEABCDEABCDEPABCDEABCDEPABCDEABCD';

$otext=~ s/([E])/$1=/g; #Main cut rule.

$otext=~ s/=P/P/g;

@output = split( /\=/, $otext);

print "@output";

Please do 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-09T19:07:11+00:00Added an answer on June 9, 2026 at 7:07 pm

    To split on “E” except where it’s followed by “P”, you should use Negative look-ahead assertions.

    From perldoc perlre “Look-Around Assertions” section:

    • (?!pattern)
      A zero-width negative look-ahead assertion.
      For example /foo(?!bar)/ matches any occurrence of “foo” that isn’t followed by “bar”.
    my $otext = 'ABCDEABCDEABCDEPABCDEABCDEPABCDEABCD'; 
    #                E    E    EP    E    EP    E
    my @output=split(/E(?!P)/, $otext); 
    use Data::Dumper; print Data::Dumper->Dump([\@output]);"
    
    $VAR1 = [
              'ABCD',
              'ABCD',
              'ABCDEPABCD',
              'ABCDEPABCD',
              'ABCD'
            ];
    

    Now, in order to NOT cut at occurences #2 and #4, you can do 2 things:

    1. Concoct a really fancy regex that automatically fails to match on given occurence. I will leave that to someone else to attempt in an answer for completeness sake.

    2. Simply stitch together the correct fragments.

      I’m too brain-dead to come up with a good idiomatic way of doing it, but the simple and dirty way is either:

        my %no_cuts = map { ($_=>1) } (2,4); # Do not cut in positions 2,4
        my @output_final;
        for(my $i=0; $i < @output; $i++) {
            if ($no_cuts{$i}) {
                $output_final[-1] .= $output[$i];
            } else {
                push @output_final, $output[$i];
            } 
        }
        print Data::Dumper->Dump([\@output_final];
      
        $VAR1 = [
                  'ABCD',
                  'ABCDABCDEPABCD',
                  'ABCDEPABCDABCD'
                ];
      

      Or, simpler:

        my %no_cuts = map { ($_=>1) } (2,4); # Do not cut in positions 2,4
        for(my $i=0; $i < @output; $i++) {
            $output[$i-1] .= $output[$i]; 
            $output[$i]=undef; # Make the slot empty
        }
        my @output_final = grep {$_} @output; # Skip empty slots
        print Data::Dumper->Dump([\@output_final];
      
        $VAR1 = [
                  'ABCD',
                  'ABCDABCDEPABCD',
                  'ABCDEPABCDABCD'
                ];
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started learning haskell yesterday and I got stuck on a problem. After a
I asked a question yesterday which got answers but didnt answer the main point.
I asked some similar questions [1, 2] yesterday and got great answers, but I
Thanks to some help I received yesterday I've got some dynamic summing working on
I posted a question about keys yesterday, and got very helpful responses. I've been
I'm sure my app worked right until yesterday, when I got this error: Failed
I asked a question yesterday on here and got some awsome help, but I
I need to display yesterday's (preivious one of current date) using QT. I got
So I asked a similar question yesterday, and got a great response - I'm
This is a expansion on to a previous question that got answered yesterday, which

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.