Click here to get back home

Shebang line for modules?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Shebang line for modules? Steve Roscio 01-08-2008
Posted by Claudio Calvelli on January 9, 2008, 9:51 am
Please log in for more thread options
> Not quite true. You can set the $^W variable directly.
>
> package MyPackage;
> use strict;
> local $^W = 1;
>
> Btw, by localizing it, warnings would not be enabled outside the
> package, right?

They would not even be enabled inside the package though. The "local" will
mean that $^W is one during the module initialization, but not when its
code is called later. For example:

------ TEST.pm -------
package TEST;

use strict;
local $^W = 1;

print "in TEST: $^W=$^W\n";

sub w {
print "in TEST:w(): $^W=$^W\n";
}

1;
----------------------

-------- test --------
#!/usr/bin/perl

use TEST;

TEST::w();
print "outside TEST: $^W=$^W\n";
----------------------

Now type "perl test" or your OS's equivalent and you get:

------ results -------
in TEST: $^W=1
in TEST::w(): $^W=0
outside TEST: $^W=0
----------------------

note how $^W is zero when TEST::w() is called.

You could add "local $^W = 1" at the start of every sub within your package,
but that would enable warnings in any subroutine called from it, even if it
is in another package, which is probably bad manners.

C.
--
Real email address: join('@', 'intercal', 'sdf.lonestar.org')
It helps the spam filter if you include the word CAMEL in the subject.

Posted by Gunnar Hjalmarsson on January 9, 2008, 6:10 pm
Please log in for more thread options
Claudio Calvelli wrote:
>> You can set the $^W variable directly.
>>
>> package MyPackage;
>> use strict;
>> local $^W = 1;
>>
>> Btw, by localizing it, warnings would not be enabled outside the
>> package, right?
>
> They would not even be enabled inside the package though. The "local" will
> mean that $^W is one during the module initialization, but not when its
> code is called later.

Which wouldn't have been necessary to point out, if you hadn't snipped
my next sentence ("... only catch compile time warnings"). :(

> You could add "local $^W = 1" at the start of every sub within your package,

Those subs that are intended to be called from outside the package would do.

> but that would enable warnings in any subroutine called from it, even if it
> is in another package, which is probably bad manners.

That's a philosophical aspect on which I for one have no firm opinion. ;-)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Claudio Calvelli on January 10, 2008, 3:50 am
Please log in for more thread options
> Claudio Calvelli wrote:
> Which wouldn't have been necessary to point out, if you hadn't snipped
> my next sentence ("... only catch compile time warnings"). :(

Sorry about that - I failed completely to even see it.
Now, if newsreader software could have a "warning: posting before
full caffeination" this wouldn't happen.

C
--
Real email address: join('@', 'intercal', 'sdf.lonestar.org')
It helps the spam filter if you include the word CAMEL in the subject.

Posted by Peter Scott on January 9, 2008, 10:25 am
Please log in for more thread options
On Tue, 08 Jan 2008 14:31:51 -0700, Steve Roscio wrote:
> Does it makes sense to include a shebang line at the top of a .pm file?

Maybe:

        http://www.ddj.com/web-development/184416165

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


Posted by Steve Roscio on January 9, 2008, 4:21 pm
Please log in for more thread options
Thanx everyone! In my case it was a "stylistic" question, I had
wondered what was the defacto convention. I changed all my stuff
to 'use warnings' since that suited.

Similar ThreadsPosted
XML::Generator::DBI - use of uninitialized value on line 180 and 187 September 12, 2004, 8:00 pm
XPath to Line Number? June 26, 2007, 2:39 pm
Blank line precedes prompt June 1, 2006, 9:58 am
changing $/ new line default character December 18, 2006, 11:03 am
First line in body of Mail::POP3Client March 23, 2007, 9:43 am
Search for a job online from command line May 31, 2007, 5:44 am
Search eBay from command line May 31, 2007, 11:33 am
Creating FULLTEXT index OK on command line, but NOT with DBI...? March 12, 2005, 6:24 am
Start printing at the end of the previous line in Perl July 18, 2006, 10:51 am
Namespace is changed before "package" line is reached November 30, 2007, 1:49 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap