"be consistent" PerlMonks

### Re: Re: Re: Re: buffering question

by chipmunk (Parson)
 on Aug 29, 2001 at 07:36 UTC Need Help??

in reply to Re: Re: Re: buffering question

It turns out that the value of \$| can't be -1. This variable has special magic that only allows its value to be 0 or 1. Any true value assigned to \$| becomes 1, and any false value becomes 0. So, \$|++ and \$|=1 really are interchangeable.

Interestingly, \$|-- and \$|=0 are not interchangeable. If \$| is 1, \$|-- will of course set it to 0, but if \$| is 0, \$|-- will set it to 1!

Similar magic can be found, for example, in the \$. variable, which can only hold an integer.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: buffering question
by Rudif (Hermit) on Aug 29, 2001 at 22:33 UTC
Thank you, chipmunk, for setting me straight on this one.

My C upbringing showed up, and I did not test what I presumed was the behavior of \$| :-(

Update </b

Now that I did test it, turns out to be even more interesting. Running this

```print \$|++ for (0..9);  print"   post ++\n";
print \$|-- for (0..9);  print"   post --\n";
print ++\$| for (0..9);  print"   pre ++\n";
print --\$| for (0..9);  print"   pre --\n";
prints this
```0111111111   post ++
1010101010   post --
1111111111   pre ++
0101010101   pre --
Creative use of this  \$|-- behavior, anyone?

Re: Re: Re: Re: Re: buffering question
by blakem (Monsignor) on Aug 29, 2001 at 07:48 UTC
Cool, you're right. I just tried it out (should have probably done that *before* I posted) and \$| does only ever store the values '0' and '1'.

Thanks for the correction, I appreciate it.

-Blake

Re: Re: Re: Re: Re: buffering question
by John M. Dlugosz (Monsignor) on Aug 29, 2001 at 08:48 UTC
Wow, that's good food for an obfu. \$_=\$|=42;

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://108674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-02-28 23:13 GMT
Voting Booth?
My favourite way to spend a leap day ...

Results (26 votes). Check out past polls.