Usage of defined with Filehandle and while Loop

后端 未结 3 450
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 20:30

While reading a book on advanced Perl programming(1), I came across this code:

while (defined($s = <>)) {
    ...

Is there

3条回答
  •  独厮守ぢ
    2021-01-20 21:19

    while($line=){
        chomp($line);
    if(***defined*** $line){
        print "SEE:$line\n";
    }
    }
    __DATA__
    1
    0
    3
    

    Try the code with defined removed and you will see the different result.

提交回复
热议问题