What does "while~<>" mean?

Discussion in 'Perl Misc' started by J Krugman, Mar 26, 2005.

  1. J Krugman

    J Krugman Guest

    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

    --
    To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
     
    J Krugman, Mar 26, 2005
    #1
    1. Advertising

  2. J Krugman wrote:

    > 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;
    }
     
    Brian McCauley, Mar 26, 2005
    #2
    1. Advertising

  3. J Krugman

    Bob Walton Guest

    Brian McCauley wrote:

    > J Krugman wrote:

    ....

    > ~1 is 4294967294 (assuming 64 bit integers)

    32---------------------------^^
    ....
    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
     
    Bob Walton, Mar 26, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pratip Mukherjee

    Help: what does this VHDL code mean?

    Pratip Mukherjee, Jun 22, 2005, in forum: VHDL
    Replies:
    16
    Views:
    1,290
    Kim Enkovaara
    Jun 27, 2005
  2. Vineet Jain
    Replies:
    9
    Views:
    455
    Fredrik Lundh
    Apr 16, 2004
  3. Li Ma
    Replies:
    1
    Views:
    2,312
    Roedy Green
    Mar 9, 2009
  4. Rahul
    Replies:
    4
    Views:
    601
    Robert Kern
    Apr 7, 2009
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,232
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page