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

  • Home
  • SEARCH
  • 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 9163179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:23:02+00:00 2026-06-17T14:23:02+00:00

I have heard and read about flip-flops with regular expressions in Perl and Ruby

  • 0

I have heard and read about flip-flops with regular expressions in Perl and Ruby recently, but I was unable to find how they really work and what the common use cases are.

Can anyone explain this in a language-agnostic manner?

Now that I understand what it is, and how it works, I would rephrase the question to be simply: What is a flip-flop operator?

  • 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-17T14:23:03+00:00Added an answer on June 17, 2026 at 2:23 pm

    The flip-flop operator in Perl evaluates to true when the left operand is true, and keeps evaluating to true until the right operand is true. The left and right operand could be any kind of expression, but most often it is used with regexes.

    With regexes, it is useful for finding all the lines between two markers. Here is a simple example that shows how it works:

    use Modern::Perl;
    
    while (<DATA>)
    {
        if (/start/ .. /end/)
        {
            say "flip flop true: $_";
        }
        else
        {
            say "flip flop false: $_";
        }
    }
    
    __DATA__
    foo
    bar
    start
    inside
    blah
    this is the end
    baz
    

    The flip flop operator will be true for all lines from start until this is the end.

    The two dot version of the operator allows first and second regex to both match on the same line. So, if your data looked like this, the above program would only be true for the line start blah end:

    foo
    bar
    start blah end
    inside
    blah
    this is the end
    baz
    

    If you don’t want the first and second regexes to match the same line, you can use the three dot version: if (/start/ ... /end/).

    Note that care should be taken not to confuse the flip-flop operator with the range operator. In list context, .. has an entirely different function: it returns a list of sequential values. e.g.

    my @integers = 1 .. 1000; #makes an array of integers from 1 to 1000. 
    

    I’m not familiar with Ruby, but Lee Jarvis’s link suggests that it works similarly.

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

Sidebar

Related Questions

We have all read about or heard about the stack class, but many of
I have occasionally heard or read about people asserting their interfaces in a unit
I have heard a lot about anti patterns and would like to read a
I have heard that 'better-fit' is pretty commonly used, but I don't seem to
I have already heard about the curl library, and that I get interest about...
I've read every other thread on this and have tried everything but the Build
Have anyone of you ever heard about some KDE or GNOME (GUI in general)
I've read about unit testing and heard a lot of hullabaloo by others touting
Functional Languages - I have heard about them a lot. A related thread Best
I have heard several podcasters (most recently the guys on DotNetRocks ) say that

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.