Berkeley CSUA MOTD:Entry 31135
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/06/22 [General] UID:1000 Activity:popular
6/22    

2004/7/2-4 [Uncategorized] UID:31135 Activity:low
7/2     From yesterday's motd:
                while ( $line = <> ){
                      if ( $line !~ /line/ ) {
                                $output[$count++]=$line;
                                next;
                        }
                        if ( ! $firstline ) {
                                $firstline = $line;
                                $firstindex = $count++;
                        } else {
                                $output[$firstindex]=$line;
                                $output[$count++]=$firstline;
                        }
                }
                print foreach @output;
                # (Approximately)  -tom
        From the context, the 2nd line of this is meant to mean
            "if the current line does not contain the regexp 'line'"
        But why does !~ do this?
        \_ !~ is the shorthand for (! $foo =~ /blah/)
        \_ equivalent in this case would be: unless ($line =~ /line/) {
        \_ someone repost the whole thing please, I missed it
           \_ that is the whole thing.