Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • See also

    $ perl -wle'print $|++ for 1 .. 10'     
    0
    1
    1
    1
    1
    1
    1
    1
    1
    1

    $| only has two values, 0 and 1. I thought this was documented in perlvar but it doesn't seem to be. Perhaps it should be.

    • Yes, it has a range of [0,1], so I would expect it to stay at 1 when continually incremented. I don't, however, expect it to be incremented to 1 when it is 0 and decremented. I expect:

      0 -> 1 when $|++
      1 -> 1 when $|++
      1 -> 0 when $|--
      0 -> 0 when $|--

      I think the range should be documented, but is it going from a value of 0 to 1 when decremented a bug, or is it a documentation issue? (Of course, once you document a bug is a feature, it isn't a bug anymore :)

      • I suppose that as it's a boolean value, then the -1 gets mapped to "true" - or 1. Not sure how intuitive that is tho'.

        Of course, if you ever needed a flip-flop variable then you could make use of this behaviour :)

        $ perl -wle'print $|-- for 1 .. 10'
        0
        1
        0
        1
        0
        1
        0
        1
        0
        1
        • Yeah, I don't think it is intuitive. I guess it should just be documented somewhere that this is the case with Perl's special boolean vars. I don't like it though, it isn't DWIM.