Refs of filehandles 
Author Message
 Refs of filehandles

hi all,

I've been trying to put together a 5.000 class for telnet, sockets,
that kind of thang (if you know of one, please e-mail me). And I've
been having problems with refs of file handles.

I saw Larry's about passing refs back, i.e.,

        open(FH,_expr_);
        $self = \*FH; bless $self;

But I've discovered that I do not understand type globs and file
handles well enuf. To explain, I've cooked up the following:
but i don't know why sub slurp works at all?!?

#!/usr/pkg/bin/perl
#
#       experimenting with passing filehandles

require 5.000;
package phile;

sub new {

    open(FH, $name);            # open some file
    my $self = \*FH; bless $self;
    $self;

Quote:
}

sub slurp {
    my $self = shift;
    return <$self>;

# alternatively, this
    #local (*fh) = $$self;
    #return <fh>

Quote:
}

package main;

$ph = new phile "foobar";
print $ph->slurp;

-----
my question is, what does it work? I can understand the commented
out lines "local (*fh) ...", but why does <$self> work also?

Can someone please enlighten me. I want to make sure I'm using
the preferred syntax and construction.

-chris

.sig = New son :) No Mo' Time for Hobbies :( = .sig



Mon, 28 Apr 1997 07:37:39 GMT  
 Refs of filehandles

:hi all,
:
:I've been trying to put together a 5.000 class for telnet, sockets,
:that kind of thang (if you know of one, please e-mail me). And I've
:been having problems with refs of file handles.
:
:I saw Larry's about passing refs back, i.e.,
:
:       open(FH,_expr_);
:       $self = \*FH; bless $self;

...

:my question is, what does it work? I can understand the commented
:out lines "local (*fh) ...", but why does <$self> work also?

If $self is a real typeglob, you can use it for a filehandle.
The problem is making new ones.

    my $FH = *{ "file handle sym" . ++$Private_Count };
    return bless $FH;

should work.

--tom
--

A factor of 3000 is actually significant --Andrew Hume



Mon, 28 Apr 1997 20:36:40 GMT  
 Refs of filehandles

Quote:


>:hi all,
>:
>:I've been trying to put together a 5.000 class for telnet, sockets,
>:that kind of thang (if you know of one, please e-mail me). And I've
>:been having problems with refs of file handles.

I'm writing a package (several actually) to handle the actual
sockethandles. Would like an alpha version?

Its the InetHandle package and its subclasses and associated classes.
I'd have finished it a long time ago, except that everytime I
came across something that could be abstracted out, I had to design
a new package (like AlarmCall for nested alarms, and SelectCall
for a nice more perl-like interface to select(2)).

But I'm nearing a releasable version.

BTW how come you can't be reached by email? I tried

gave finger info on you, but the mailhost at franc.ucdavis.edu
insists it doesn't know you.
--

If you only have a hammer, you tend to see every problem as a nail.
                -- Maslow



Mon, 28 Apr 1997 21:44:44 GMT  
 Refs of filehandles

: :hi all,
: :
: :I've been trying to put together a 5.000 class for telnet, sockets,
: :that kind of thang (if you know of one, please e-mail me). And I've
: :been having problems with refs of file handles.
: :
: :I saw Larry's about passing refs back, i.e.,
: :
: :     open(FH,_expr_);
: :     $self = \*FH; bless $self;
:
: ...
:
: :my question is, what does it work? I can understand the commented
: :out lines "local (*fh) ...", but why does <$self> work also?
:
: If $self is a real typeglob, you can use it for a filehandle.
: The problem is making new ones.
:
:     my $FH = *{ "file handle sym" . ++$Private_Count };
:     return bless $FH;
:
: should work.

You need a \ in there to make the glob into a reference.  A typeglob
isn't condidered a reference by bless().

Larry



Tue, 06 May 1997 04:38:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How do I combine filehandles, refs and strict?

2. Filehandle [socket] refs

3. help: push array refs into hash, sort by refs in hash

4. ref doesn't return FileHandle for FileHandles?

5. print to filehandle when filehandle is a $var

6. ANNOUNCE: FileHandle::Rollback - FileHandle with rollback and commit

7. Redirecting filehandle to multiple filehandles

8. Benchmark: local filehandle vs. Filehandle.pm

9. global filehandle, dereferencing filehandle

10. Use strict 'refs' and indirect filehandles.

11. refs & wrappers

12. Q: efficient string copy without using refs

 

 
Powered by phpBB® Forum Software