473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Passing File Handles

Is it possible to pass the file handle from one module to the other module?

my sample code is
Test.pl
-----------
&create_top(*LOG_FILE);

Create_Top.pm
-----------------------
package Create_Top;
sub create_top {
local *LOG_FILE = $_[0];
print LOG_FILE " Test \n";
}
1;

but this code is not working, can anyone pls suggest me the best solutions????
Aug 16 '07 #1
1 1982
miller
1,089 Expert 1GB
The easily method to accomplish this is simply to use indirect filehandles

perlopentut Indirect Filehandles

Alternatively, you can create your own indirect file handle by passing a reference to the typeglob.


Expand|Select|Wrap|Line Numbers
  1. # Test.pl
  2. create_top(\*LOG_FILE);
  3.  
Expand|Select|Wrap|Line Numbers
  1. #Create_Top.pm
  2. package Create_Top;
  3.  
  4. sub create_top {
  5.     my ($fh) = @_;
  6.     print $fh " Test \n";
  7. }
  8. 1;
  9.  
You cannot however pass typeglobs directly.

- Miller
Aug 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dan | last post by:
Hello Has anybody tried to open a socket to connect to a server on page a.php and then passing it throung a session variable and getting it back at page b.php and use it there. Ive tried that...
4
by: Chris | last post by:
I'm trying to come up with a not-so-ugly manner of passing many command-line options between modules. I have a Steering.py file, which contains my main() and handles the getopts getting of...
5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
6
by: csvka | last post by:
Hello, I wonder if I could pick your brains. I'm beginning to learn about C++. I have opened a file in my program and I want to read lines from it. I would like this to be done in a separate...
9
by: Bruce | last post by:
How can I create a method that will take any object derived from a base class as a reference parameter? Something like this: void DestroyObject(ref BaseObject obj) { obj.Dispose(); obj =...
2
by: Stephen Costanzo | last post by:
My goal is to open Form2 from Form1 and have Form2 pass back an integer to Form 1. In VB, this is rather simple: Form 1 (vanilla form with a button): Dim WithEvents x As Form2 Dim i As...
7
by: Anne | last post by:
hie there, i want to be able to pass multiple parameters to another page. currently, i am able to do so, but somehow i feel it is not the correct way to do it. below is part of what i have so far....
8
by: Robert | last post by:
I am creating a small help browser. It is pretty much finished except I cannot find how to pass a file to it (i.e. browser.exe index.html, or any html file, and the html file opens in the browser)...
3
by: Subodh | last post by:
Hi All, In C++ we could pass a constant reference to a function so that the target function could not modify the objects passed eg. const classA & dummmyfunction(const classB) similar thing...
4
Vkas
by: Vkas | last post by:
HELLO!!!!!!!!!!!!! me using ASP.net 2.0, language VB.net! working tool Visula studio.Net 2005 I HAVE CREATED A simple WEB User control (calender.ascx) having a text box , a button, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.