in reply to Reading in Block

I would tend to use flip-flopping indeed for this kind of thing:
my $speaking = 1; my $speaker, %words; for (<>) { chomp; s/^\s+//; s/\s+$//; if ( /\-\-\-/ ) { $speaking = !$speaking; } elsif( $speaking ) { $words{ $speaker } += scalar split( /\s+/ ); } else { $_ and $speaker = $_; } }

One world, one people

Replies are listed 'Best First'.
Re^2: Reading in Block
by toolic (Bishop) on Feb 24, 2011 at 14:30 UTC
    if ( /\-\-\-/ ) {
    can be coded as (to reduce back-whackin')...
    if ( /\Q---/ ) {
    or even as ...
    if ( /---/ ) {
    since dash is not a special character in this regex context.
Re^2: Reading in Block
by TomDLux (Vicar) on Feb 24, 2011 at 15:28 UTC

    Forgive me for being picky, but I don't see a flip-flop operator in this example. The flip-flop consists of an if which has two tests joined by a range. See Range Operators in perldoc perlop.

    if ( <some cond or re> .. <another test or re> ) { ... }

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

      I never said there was a Perl flip-flop operator. OK the OP did say flip-flop matching which implies yet a third thing to be just as picky. But I presented $x = !$x in my code suggestion as the simplest implementation in Perl of a flip-flop I can think of, irrespective of what it's used for.

      One world, one people