in reply to Setting a filehandle attribute for just one filehandle
#!/usr/bin/perl -w use strict; package MyHandle; use Tie::Handle; use IO::Handle; use base 'Tie::StdHandle'; my %seps; sub READLINE { my $self = shift; local $/ = $seps{$self}; $self->SUPER::READLINE(@_); } sub set_input_separator { my $self = shift; $seps{$self} = shift; } sub DESTROY { delete $seps{shift}; } package main; my $fh = tie *FH2, 'MyHandle'; $fh->set_input_separator( "\007" ); open FH1, 'test1.txt'; open FH2, 'test2.txt'; while (<FH1>) { my $data1 = $_; chop($data1); my $data2 = <FH2>; chop($data2); print "(1)$data1\n(2)$data2\n"; }
update: added DESTROY to avoid mem leaks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(bbfu) Re(2): Setting a filehandle attribute for just one filehandle
by bbfu (Curate) on Jun 27, 2001 at 10:12 UTC | |
by bikeNomad (Priest) on Jun 27, 2001 at 18:42 UTC | |
by bbfu (Curate) on Jun 27, 2001 at 19:30 UTC |