develooper Front page | perl.perl5.porters | Postings from February 2011

I/O layers and magic <ARGV>

Thread Next
Tom Christiansen
February 26, 2011 21:07
I/O layers and magic <ARGV>
Message ID:
Is there any known issue with, or trick for, controlling the 
I/O layers on magic <ARGV>?  At runtime, I want to do this:

    if (something)
	set input type to :bytes
    elsif (something else) 
	set input type to :utf8
    elsif (yet another something)
	set input type to :encoding($whatever)

    while (<>) {


And I'm having the strangest troubles getting that to work.

You can't binmode it, because it isn't opened yet -- plus
it tends to move around.

Neither I have been able to finagle some sort of 


that seems to do any good.  Not sure why.  It just doesn't take.

It needs to work on <ARGV> no matter whether it's reading 
from STDIN or iterating through @ARGV.

Is there some pragmatic incantation I'm forgetting?

The idea is that the program should be able be called with
some option or another, and behave the same way whether
it's reading from stdin or from the catenated @ARGV:

    % prog --bytes < input
    % prog --bytes input1 input2 input3

    % prog --utf8 < input
    % prog --utf8 input1 input2 input3

    % prog --input-encoding=crlf:UTF-16 < input
    % prog --input-encoding=crlf:UTF-16 input1 input2 input3

Do I really have to throw out magic <ARGV> and do 
all the work myself?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About