For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > Want to add exception for a auto run sub in module









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Want to add exception for a auto run sub in module
Jimmy

2006-01-23, 7:56 am

Hi all,

I have a module somewhat looks like this :

package minicgi;
require Exporter; our @ISA = qw/Exporter/;
our @EXPORT = qw/NormalHeader OtherHeader/;

sub NornalHeader { print "Content-Type:text/html\n\n" } # normal html
sub OtherHeader { print "Content-Type:$_[0]\r\n\r\n" } # perhaps sending file

NormalHeader;
1;


So, when I use minicgi, normal_header() will autorun, however,
it makes the other_header() meaningless. So my question is,
is there anyway I'll run normal_header() without specific argument,
but don't run it if I pass whatever argument on the 'use' statement ?

Thank you very much,
Jim

Jimmy

2006-01-23, 7:56 am

Sorry for typing err for the sub name at the question part =(
normal_header() and other_header() should aling with the
sample code, so is NormalHeader() and OtherHeader().


----- Original Message -----
From: "Jimmy" <perl@reborn.org>
To: "Perl Beginners" <beginners@perl.org>
Sent: Monday, January 23, 2006 8:17 PM
Subject: Want to add exception for a auto run sub in module


Hi all,

I have a module somewhat looks like this :

package minicgi;
require Exporter; our @ISA = qw/Exporter/;
our @EXPORT = qw/NormalHeader OtherHeader/;

sub NornalHeader { print "Content-Type:text/html\n\n" } # normal html
sub OtherHeader { print "Content-Type:$_[0]\r\n\r\n" } # perhaps sending
file

NormalHeader;
1;


So, when I use minicgi, normal_header() will autorun, however,
it makes the other_header() meaningless. So my question is,
is there anyway I'll run normal_header() without specific argument,
but don't run it if I pass whatever argument on the 'use' statement ?

Thank you very much,
Jim


Tom Phoenix

2006-01-23, 6:56 pm

On 1/23/06, Jimmy <perl@reborn.org> wrote:

> is there anyway I'll run normal_header() without specific argument,
> but don't run it if I pass whatever argument on the 'use' statement ?


I believe you're asking how a module can determine how it was 'use'd,
so as to provide default behavior when no import list is specified.
The documentation for 'use' in the perlfunc manpage covers the
'import' method, which is called when the import list is not missing;
does that give you what you need? Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com