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

Re: PerlIO ":pop" / more elegant interface

Nick Ing-Simmons
February 14, 2003 14:31
Re: PerlIO ":pop" / more elegant interface
Message ID:
Alex Efros <> writes:
>>    open($fh,...)
>>    ...
>>    binmode($fh,":encoding(...)");  # next chunk is encoded
>>    ...
>>    binmode($fh,":pop");            # back to un-encocded
>>    A more elegant (and safer) interface is needed.
>If PerlIO layers realized as stack/array, why not allow to edit them as array?

They are implemented as a singly linked list of C structs.
The other muddle is socket file-handles can have _two_ PerlIO lists
one for input and the other for output.
Mapping that on to a "stack/array" is not as trivial as it looks at first
but not hard.

>    open($fh,...)
>    ...
>    push @$fh, ":encoding(...)";
>    ...
>    pop @$fh;
>    ...
>    $_ = ":encoding(koi8-r)" for first {/encoding/} @$fh;
>    ...

Hmm - I though @$fh with $fh being a ref-to-glob would access the AV
That is 

my $ref = \*FOO;

Would update @FOO 

But is seems it doesn't (anymore?)

Which may mean the syntax is available for this.
However the "arrays" are going to be very odd - e.g. your examples show 
items as strings and they are not strings - nearer objects, 
so some kind of implied-new is going on. (Which is not alien to the warped mind
that devised perl/Tk - but which may be  bit gross to go in the core...)


   push @$fh, ":encoding(koi8-r)";

would really have to be short-hand for something more like 

   push @$fh,PerlIO::layer->findClass('encoding')->construct('koi8-r');

And what would 

my $layer = pop($fh);

Set $layer to ? - if $layer is re-pushed should it remember the data it had

etc. etc.

Copied to p5p as such ideas need wider discussion.

Nick Ing-Simmons Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About