$| can never be -1, unless someone has tied it to some class, or has set it via a typeglob:
tie $|, 'Pkg', ...; # or *| = *foo; $foo = 100; print $|; # 100!
But those are really esoteric cases; and if you're really panicky, just say $| = 0 or $| = 1.

For those interested, $| is as good as a boolean:

/* in sv.h */ #define IOf_FLUSH 4 /* in mg.c -- the magic file */ /* in Perl_magic_get() */ case '|': sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 ); break; /* in Perl_magic_set() */ case '|': { IO *io = GvIOp(PL_defoutgv); if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0) IoFLAGS(io) &= ~IOf_FLUSH; else { if (!(IoFLAGS(io) & IOf_FLUSH)) { PerlIO *ofp = IoOFP(io); if (ofp) (void)PerlIO_flush(ofp); IoFLAGS(io) |= IOf_FLUSH; } } } break;
Perl_magic_get() ends up returning a 0 or a 1 (which is what you get when you fetch the value of $|). Perl_magic_set() determines whether the value you're setting $| to is true or false, and sets or unsets the IOf_FLUSH bit accordingly.

japhy -- Perl and Regex Hacker

In reply to Re: $ = 0 at start of script by japhy
in thread $|= 0 at start of script by pileswasp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.