Last Updated: February 25, 2016
·
419
· tiger-222

Reading from STDIN, the good way

Good replacement for <STDIN> to avoid perlcritic warn : Use <> or <ARGV> or a prompting module instead of <STDIN>:

sub _stdin {
    my $io;
    my $string = q{};

    $io = IO::Handle->new();
    if ( $io->fdopen(fileno(STDIN), 'r') ) {
        $string = $io->getline();
        $io->close();
    }
    chomp $string;
    return $string;
}