Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ruby got its flip-flop operator from Perl, which in turn got it from sed and awk. It can be really useful for keeping simple state, e.g.:

    # parse mail messages
    while (<$email>) {
        $in_header =   1  .. /^$/;
        $in_body   = /^$/ .. eof;
        if ($in_header) {
            # do something
        } else { # in body
            # do something else
        }
    }

And other examples at http://perldoc.perl.org/perlop.html#Range-Operators


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: