S
Sniff
I have been working with Perl for a few months now and in my latest
program I decided to give Perl OO a try.
In an object I'm trying to use a Filehandle (or Glob) which is uses to
communicate with a child. I have been trying to keep these handles in
an instance variable but it doesn't seem to work. I have tried a few
different ways but I think I'm having issues dereferencing the
variables.
Here are some of the ways I have tried to do this:
In my class constructor I do this:
my $fhw = *write{FILEHANDLE};
$self->{"WRITE"} = $fhw;
# ... repeated for READ, ERROR ...
# Then I call open3 with those 3 handles
open3( $self->{"WRITE"}, $self->{"READ"}, $self->{"ERROR"},
"worker.pl" );
Later in a method I tried :
print $self->{"WRITE"} "$someMessage\n" ; # this creates a syntax
error, why?
I also tried this:
In the class constructor:
$self->{"WRITE"} = \*WRITE; #using a reference to a globtype
#later on I call open3 as I did above
Then in a method I tried :
print {$self->{"WRITE"}} "$message\n" ; #No error but I don't
think it worked
My first version of all this code was written in non-OO style and it
works fine, but I was using a bareword (i.e. *WRITE) for the file
handles. Any help would be appreciated.
program I decided to give Perl OO a try.
In an object I'm trying to use a Filehandle (or Glob) which is uses to
communicate with a child. I have been trying to keep these handles in
an instance variable but it doesn't seem to work. I have tried a few
different ways but I think I'm having issues dereferencing the
variables.
Here are some of the ways I have tried to do this:
In my class constructor I do this:
my $fhw = *write{FILEHANDLE};
$self->{"WRITE"} = $fhw;
# ... repeated for READ, ERROR ...
# Then I call open3 with those 3 handles
open3( $self->{"WRITE"}, $self->{"READ"}, $self->{"ERROR"},
"worker.pl" );
Later in a method I tried :
print $self->{"WRITE"} "$someMessage\n" ; # this creates a syntax
error, why?
I also tried this:
In the class constructor:
$self->{"WRITE"} = \*WRITE; #using a reference to a globtype
#later on I call open3 as I did above
Then in a method I tried :
print {$self->{"WRITE"}} "$message\n" ; #No error but I don't
think it worked
My first version of all this code was written in non-OO style and it
works fine, but I was using a bareword (i.e. *WRITE) for the file
handles. Any help would be appreciated.