Why does perl take a file name provided on the command line and open it for use with standard input? How should I prevent that?
I'm working on a program that takes a couple of files as command line arguments. At some point in the program, I want to prompt the user for an action to take.
The lines that accept the user's response look something like this:
print "Remove '$origin'? ([Y]es, [N], A(ll), ne[V]er; default: N) "; my $answer = <>; print "answer: |$answer|\n" if (DEBUG); chomp($answer); $answer = lc($answer); if ($answer eq ('y' or 'yes')) { unlink $origin; }
The problem is that <> is filled with the content of the first file on the command line. This is entirely unexpected. Why would the file be opened at all? I would have expected that filename to be treated only as a scalar value.
I confirmed this by adding while (<>) { print; } before I prompted for an answer.
To double-check, and eliminate problems caused by modules or other code, I put that line into a separate script and got the same results:
Thank you.#!/usr/bin/perl -w use strict; while (<>) { print; }
In reply to unexpected STDIN by GhodMode
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |