in reply to open $self->{FILE}

I can't imagine that's the best way to approach your problem. The package that $self is an instance of should implement its own accessor and keep a private filehandle, so that your code might look like:

$self->open(">>$self->{file_path}$self->{file_name}"); $self->print "some text here\n"; $self->close;

Perhaps if you gave us a little more background about what you're trying to accomplish, we might be able to help you find a different approach.

radiantmatrix
require General::Disclaimer;
"Users are evil. All users are evil. Do not trust them. Perl specifically offers the -T switch because it knows users are evil." - japhy

Replies are listed 'Best First'.
Re^2: open $self->{FILE}
by revdiablo (Prior) on Nov 05, 2004 at 20:39 UTC

    I think his question is how to implement something like the methods you've shown. He's asking how to do it in from inside the object, thus he's trying to access the object's data members. At least, that's the impression I got...

      If you're correct...

      package Something; .... #package stuff sub print { my $self = shift; my $FH = $self->{FILE}; #deref the FILE handle return print $FH join('',@_); } #and likewise with others.

      The above would be easier to read and maintain than the whole print { $self->{FILE} } "text" notation, IMO.

      radiantmatrix
      require General::Disclaimer;
      "Users are evil. All users are evil. Do not trust them. Perl specifically offers the -T switch because it knows users are evil." - japhy