in reply to Re^2: blank lines up to a point
in thread blank lines up to a point

This works as a quirk of the flip/flop operator. From the documentation "If either operand of scalar ``..'' is a constant expression, that operand is implicitly compared to the $. variable, the current line number." The statement scalar tell(STDIN) must set $. = 0 (although I don't know why) changing the line from scalar tell(STDIN); to $. = 0; gives the same result.

use strict; use warnings; my $firsttime = 1; my $line1 = <DATA>; print neverflop(); $firsttime = 0; my $line2 = <DATA>; print neverflop(); #scalar tell(STDIN); $. = 0; print neverflop(); print neverflop(); sub neverflop { my $statecount = ($firsttime .. 0); ($firsttime .. 0) ? "flip$statecount\t" : "flop$statecount\t"; } __DATA__ line1 line2 line3 __END__ flip1 flip2 flip3E0 flop

PJ
use strict; use warnings; use diagnostics; (if needed)

Replies are listed 'Best First'.
Re^4: blank lines up to a point
by ysth (Canon) on Sep 15, 2004 at 15:00 UTC
    $. is stored per-filehandle, and automatically refers to the last input file. Any of readline, tell, seek, sysseek, or eof will change the last input file.

    You could just use:

    /\S/ .. my $false
    instead.
      Can any operator that inspires this much confusion be a GoodThing (TM)?

      Don't answer that. It's a rhetorical question.