Clarification on chomp

后端 未结 5 1005
旧时难觅i
旧时难觅i 2021-01-18 05:39

I\'m on break from classes right now and decided to spend my time learning Perl. I\'m working with Beginning Perl (http://www.perl.org/books/beginning-perl/) and I\'m finish

5条回答
  •  走了就别回头了
    2021-01-18 06:11

    I think best practice here is to write:

    chomp(my $input = );
    

    Here is quick example how chomp function ($/ meaning is explained there) works removing just one trailing new line (if any):

    chomp (my $input = "Me\n"); # OK
    chomp ($input = "Me"); # OK (nothing done)
    chomp ($input = "Me\n\n"); # $input now is "Me\n";
    chomp ($input); # finally "Me"
    
    print "$input can be reached at $name_number{$input}\n"; 
    

    BTW: That's funny thing is that I am learning Perl too and I reached hashes five minutes ago.

提交回复
热议问题