Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Urgent: Problems with FileHandle and objects

Posted on 1999-07-01
6
Medium Priority
?
235 Views
Last Modified: 2006-11-17
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?
0
Comment
Question by:e4monsch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1213692
#as I said in response to Q.10177597
print {$self{m_filehandle}} "qwerqwerqwer";
0
 
LVL 2

Author Comment

by:e4monsch
ID: 1213693
Okay, it works! But can you tell me why it must be done like this?

Regards Jan

0
 
LVL 2

Author Comment

by:e4monsch
ID: 1213694
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


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:e4monsch
ID: 1213695
Forget the last comment. That code works.
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 1213696
perldoc -q "How can I use a filehandle indirectly"
0
 
LVL 2

Author Comment

by:e4monsch
ID: 1213697
Forget the last comment. That code works.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question