in reply to Greedy flip flop operator?

Hello chengchl,

You need this:  print if (/^start/ .. /^\[^\+]/); # EDIT: /^\[^\+]/ is wrong!

Infact your version says: print between start and (the first) + included , while mine prints between start and a not + included. ie it will print also the first new line without a leading +

The flip flop operator is already greedy: it is true between two patterns, included. In you case perhaps it's better something else: have a switch that signal if start was found and if so just print out strings starting with a + sign.

PS see also my library links

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Greedy flip flop operator?
by LanX (Saint) on Apr 26, 2018 at 07:25 UTC
    > /^\[^\+]/

    Shouldn't it rather be  /^[^+]/ ?

    I'd also test for following \w+ to avoid whitespace confusion.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery

      /^[^+]/ will end at the first empty line (if they really are there as shown).. anyway you are right: I must not post before coffe

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
        > will end at the first empty line

        Really? Can't test at the moment but an empty line shouldn't match a character class cause it requires at least one character.

        Of course you could have whitespace characters, that's why I'd include \w+

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Wikisyntax for the Monastery

      Hi Rolf, It seems it will only print the first line... When i execute the code as you instructed.
Re^2: Greedy flip flop operator?
by chengchl (Acolyte) on Apr 26, 2018 at 08:06 UTC
    Thanks L. I think we should use ... instead of .. for the flip flop operator. Thanks again!