What does "while~<>" mean?

J

J Krugman

I recently saw a Perl one-liner that ended with the construct
"while~<>". MO=Deparse was no help (it simply translated it to
"while ~<ARGV>"). I searched the Perl docs but found nothing.
What does the tilde before the <> operator mean?

Thanks!

jill
 
B

Brian McCauley

J said:
I recently saw a Perl one-liner that ended with the construct
"while~<>". MO=Deparse was no help (it simply translated it to
"while ~<ARGV>"). I searched the Perl docs but found nothing.
What does the tilde before the <> operator mean?

It is the binary not operator. It is one of the few Perl operatotions
that treats numbers differently from strings.

~1 is 4294967294 (assuming 64 bit integers)

~"\x01\x02" is "\xFE\xFD"

But this sounds like golfing to me (trying to write the smallest
possible code with no consideration given to clarity).

<> inside a while clause magically assignes $_ but ~<> supresses this.
So it simply waits for a line of input an thows it away.

foo while ~<>;

Is like

while (1) {
<>; # Pause
foo;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top