Link to home
Start Free TrialLog in
Avatar of e4monsch
e4monsch

asked on

Urgent: Problems with FileHandle and objects

G'day! I have written following method code in a object.

sub method
{
    my($self) = shift @_;    
    my($filename) = shift @_;
    $self{m_filehandle} = \*$filehandle;
    open($self{m_filehandle}, ">blabla");
    print $self{m_filehandle} "qwerqwerqwer";
    ...
}

I always get the following error:
String found where operator expected at Makefile.pm line 31, near "} "qwerqwerqwer""
        (Missing operator before  "qwerqwerqwer"?)
syntax error at Makefile.pm line 31, near "} "qwerqwerqwer""
BEGIN failed--compilation aborted at makefiletest.pl line 1.

Can someone tell me what the problem is and how to solve it?
Avatar of ozo
ozo
Flag of United States of America image

#as I said in response to Q.10177597
print {$self{m_filehandle}} "qwerqwerqwer";
Avatar of e4monsch
e4monsch

ASKER

Okay, it works! But can you tell me why it must be done like this?

Regards Jan

Another question. I have following code I always get the an error:

Can't use an undefined value as a symbol reference at v:\implementation\make\createmakefile.pl line 196.

Code:

&main();
sub main {
    my($fileHandle) = \*TEMPMAKEFILE;
    open($fileHandle, ">test.txt")
        or die("Could not create the file, stopped ");
    print $fileHandle "asdfqwer"; #works fine
    function($fileHandle);
    ...
}

sub function {
    my($filehandle) = @_;
    print $filehandle "asdf"; #produces an error
}

What's the problem here? It's really mad! Perl seems to behave absolutly asymetric! I tried to put the filehandle into braces {$filehandle} but it did not work.

Can someone tell how to correct the problem?

Regards Jan


Forget the last comment. That code works.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forget the last comment. That code works.