Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > File Handle Problem

Reply
Thread Tools

File Handle Problem

 
 
Louis
Guest
Posts: n/a
 
      09-09-2006
Hope somebody can tell me why this happens to filehandles...

I am playing with perl packages, and I had all functions in one file.
Now I want to split them into different files using package.

BEFORE: I have a function that opens a filehandle (FH1) and then calls
another function to print messages. This works good.

NOW: I put the calling function in another file. When it calls the print
function it uses &main:rtmess();, perl prints out errors: printf() Non
unopened filehandle FH1 at.....

ANd if I copy the prtmess() function in the same file as the calling
function, it works again.


My question is: I read somewhere that once you open a filehandle, perl
keeps it open until you close it. So why the different file scenario
doesn't seem to work?

Appreciate the help. Thanks.
 
Reply With Quote
 
 
 
 
Louis
Guest
Posts: n/a
 
      09-10-2006
Louis wrote:
> Hope somebody can tell me why this happens to filehandles...
>
> I am playing with perl packages, and I had all functions in one file.
> Now I want to split them into different files using package.
>
> BEFORE: I have a function that opens a filehandle (FH1) and then calls
> another function to print messages. This works good.
>
> NOW: I put the calling function in another file. When it calls the print
> function it uses &main:rtmess();, perl prints out errors: printf() Non
> unopened filehandle FH1 at.....
>
> ANd if I copy the prtmess() function in the same file as the calling
> function, it works again.
>
>
> My question is: I read somewhere that once you open a filehandle, perl
> keeps it open until you close it. So why the different file scenario
> doesn't seem to work?
>
> Appreciate the help. Thanks.

Thanks for your suggestions...with those I finally realized that the
error iss I was so concentrating on keeping the package names properly
on the functions but not on the filehandle FH1. Once I added the package
name in front of FH1 (packagename::FH1), the script works.

But now I have to figure out how to use the same prtmess function for
all the reports if some of them are in different packages.

I thought that yuou cannot pass the filehandle directly as a parameter
to a function. Maybe I can pass a reference of FH1 to the function.

Anyway, thanks very much for your input.
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      09-10-2006
Louis wrote:
> Thanks for your suggestions...with those I finally realized that the
> error iss I was so concentrating on keeping the package names properly
> on the functions but not on the filehandle FH1. Once I added the package
> name in front of FH1 (packagename::FH1), the script works.
>
> But now I have to figure out how to use the same prtmess function for
> all the reports if some of them are in different packages.
>
> I thought that yuou cannot pass the filehandle directly as a parameter
> to a function. Maybe I can pass a reference of FH1 to the function.


Sure you can, see the FAQ:

perldoc -q "How do I pass filehandles between subroutines"



John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Package to handle table text render (handle space or tab betweenthe columns) ? =?ISO-8859-1?Q?KLEIN_St=E9phane?= Python 3 10-06-2006 08:46 AM
Possible to handle web requests without an ASPX page? i.e. have DLL handle request. jdlwright@shaw.ca ASP .Net 2 05-31-2005 05:42 PM
how to handle command line output(not terminal handle) Leon Python 2 11-04-2004 05:16 AM
File Handle Reading Blues: Rereading a File Handle for Input Dietrich Perl 1 07-22-2004 10:02 AM
File pointer to file handle Apollyon C Programming 5 05-02-2004 11:35 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57