Sorry, I cannot resist. Your code is ummmm doing lots of things that I do not think are what you intend.
$ARGS = @ARGV; if ( -t and $ARGS eq 0 ) { }
The more idiomatic way of saying this is
die "No input found\n" if ( -t and @ARGV == 0 );
I would also like to point out that you are testing the wrong kind of equality in your code -- you used the string equality test ( eq ) instead of the numeric test ( == ). In this case it worked, but it will someday drive you nuts trying to hunt this kind of bug down.

$names++, shift if $ARGV[0] eq "-l";
If I have figured this out correctly, you are trying to parse some command line options. I would strongly recommend using Getopt::Long, a core module that does this job very well.

I am assuming you really mean to shift the argument you just parsed out of @ARGV. Unfortunately, shift with no arguments assumes you mean @_, which is not @ARGV. Again, it likely works in this case, but I really doubt this is your intended affect.

The same holds true for the next line.

@ARGV = "-" unless @ARGV;
This code will never be executed. I am assuming it is a hold-over from your previous problems. The 'if' at the top of the program makes certain that @ARGV has to have something in it.

The assignment back to @ARGV is a little.... ugly IMHO. It took me several tries to figure out what it is doing. I would likely write this expression as

exit 0 unless ( grep { -T or $_ eq "-" } @ARGV );
but this is likely more a stylistic thing.

Oh, good use of the -w flag. It appears, though, you forgot to use strict. It will seem a pain at first, but it will really help as your programs get longer and more complex.

Mik
mikfire


In reply to Re: Re: Re: Re: Test for standard input by mikfire
in thread Test for standard input by Anonymous Monk

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.