LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Perl OO and formats

[ILUG] Perl OO and formats

Peter Heslin Peter.Heslin at ucd.ie
Thu Feb 10 00:46:37 GMT 2000


On Wed, Feb 09, 2000 at 11:07:26AM +0000, Donncha O Caoimh wrote:
> Just got my head around Perl OO yesterday (after a lengthy time away
> from trying to figure it out, those O'Reilly books are great!) and I'm

I've been reading /Object Oriented Perl/ by Damien Conway, published
by Manning -- it's very good indeed.

> trying to print to a FORMAT from a derived function.
> I tried the obvious, 
> $self->{CUSTOMER_REPORT} = CUSTOMER_REPORT;
> in the base constructor which didn't work (didn't think it would
> though.) but I'd like to know if anyone knows a better way of using
> formats other than including the file in each function, or making them
> global variables. (Is that possible with formats even?)

I do not understand exactly what you are trying to do here, but if you
just want to treat a format as a global variable, that should be easy --
qualify it with its full package name:

use FileHandle;
my $fh = new FileHandle "> foo.txt";
$fh->format_name("My_Class::My_Subclass::My_format");
write ($fh) if defined $fh;

I would imagine that you can also pass a format to a subroutine
(or method) by passing a typeglob, just as one would do for a
filehandle or any other symbol table entry:

$self->{CUSTOMER_REPORT} = \*CUSTOMER_REPORT;
---------------------------^^

But I have never tried this myself, and now that I write this, I am
having second thoughts -- there is some special magic attached to
filehandle refs that implicitly and automatically dereferences them
upon use, and this magic may not apply likewise to formats.  It might be
worth a quick try.

Could it be that your problem is not only that you need access to the
format itself, but also that lexically scoped variables used in the
format's value list have gone out of scope (or have not even been
declared yet, since you say this is a constructor method)?

Peter




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell