I'm going to follow up a second time here...
I was thinking a little more about your question. I remember back to the days of my Econ classes, where the professor could answer just about any question with "It depends." How are you reading STDIN, and where is it getting its stream from? Let's say, for example, you've got a bunch of files listed on the command line, and you're reading them via the empty diamond operator: <> (see perlop). Before you start reading from them, @ARGV is going to have a list of filenames that were present on the command line when the script was invoked. It would be easy enough to use the -s function (perldoc -f -X) to check the file size.
my %sizes; die "Can't pre-measure a TTY stream\n" if -t; foreach( @ARGV ) { if( my $size == -s ) { $sizes{ $_ } = $size; } }
The -t test checks whether your input is coming from a terminal. If it is, as BrowserUk pointed out, you can't measure it, just as you can't tell me today what date I should mark in my calendar as the end of time as we know it.
However, even -t is not getting you the whole story. Probably the best thing to do would be to fail unless -f (unless you're looking at a file). That's because your stream could be coming from a socket or a named pipe, and rather than test each of those cases individually, you may as well just fail if you're not looking at a file.
Dave
In reply to Re: Counting the size of STDIN
by davido
in thread Counting the size of STDIN
by mikealeonetti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |