Programmatically read from STDIN or input file in Perl

前端 未结 8 1083
南方客
南方客 2020-12-12 19:45

What is the slickest way to programatically read from stdin or an input file (if provided) in Perl?

8条回答
  •  眼角桃花
    2020-12-12 20:01

    This provides a named variable to work with:

    foreach my $line (  ) {
        chomp( $line );
        print "$line\n";
    }
    

    To read a file, pipe it in like this:

    program.pl < inputfile
    

提交回复
热议问题