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:

#!/usr/bin/perl -w use strict; while (<>) { print; }

Thank you.
--
Ghodmode
www.ghodmode.com/blog

In reply to unexpected STDIN by GhodMode

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.