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 Steve Roscio on January 8, 2008, 4:31 pm
Please log in for more thread options
Does it makes sense to include a shebang line at the top of a .pm file?
For example:

#!/usr/bin/perl -w
use strict;
.
.
.


Or is it more appropriate to omit the shebang line, since the .pm isn't
"executed" per-se, and instead 'use warnings;'?

- Steve

Posted by Gunnar Hjalmarsson on January 8, 2008, 4:58 pm
Please log in for more thread options
Steve Roscio wrote:
> Does it makes sense to include a shebang line at the top of a .pm file?
> For example:
>
> #!/usr/bin/perl -w
> use strict;
> .
> .
> .
>
>
> Or is it more appropriate to omit the shebang line, since the .pm isn't
> "executed" per-se, and instead 'use warnings;'?

That sounds very much as a SAQ (Self Answered Question) to me. ;-)

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

Posted by Steve Roscio on January 8, 2008, 7:06 pm
Please log in for more thread options
Gunnar Hjalmarsson wrote:
> Steve Roscio wrote:
>> Does it makes sense to include a shebang line at the top of a .pm
>> file? For example:
>>
>> #!/usr/bin/perl -w
>> use strict;
>> .
>> .
>> .
>>
>>
>> Or is it more appropriate to omit the shebang line, since the .pm
>> isn't "executed" per-se, and instead 'use warnings;'?
>
> That sounds very much as a SAQ (Self Answered Question) to me. ;-)
>
OK, I'll take that to mean:
nuke the shebang lines, use warnings.
Thanx.

Posted by sisyphus on January 9, 2008, 3:36 am
Please log in for more thread options
> Gunnar Hjalmarsson wrote:
> > Steve Roscio wrote:
> >> Does it makes sense to include a shebang line at the top of a .pm
> >> file? =A0For example:
>
> >> #!/usr/bin/perl -w
> >> use strict;
> >> =A0 =A0.
> >> =A0 =A0.
> >> =A0 =A0.
>
> >> Or is it more appropriate to omit the shebang line, since the .pm
> >> isn't "executed" per-se, and instead 'use warnings;'?
>
> > That sounds very much as a SAQ (Self Answered Question) to me. ;-)
>
> OK, I'll take that to mean:
> =A0 =A0nuke the shebang lines, use warnings.

Except that there *are* differences between "use warnings" and the "-
w" flag. So I guess that if you wanted to enforce the "-w" switch in
preference to "use warnings", then you would have to do it via a
shebang line. (Read that last sentence as a question ... as much as an
assertion.)

I seem to recall that some people take exception to modules turning on
the "-w" switch. I think some people might even object to "use
warnings" in modules ... but I'm not au fait with the reasoning (re
either situation) off the top of my head.

Cheers,
Rob


Posted by Gunnar Hjalmarsson on January 9, 2008, 4:45 am
Please log in for more thread options
sisyphus wrote:
>> OK, I'll take that to mean:
>> nuke the shebang lines, use warnings.

Yes, that's what I meant to say.

> Except that there *are* differences between "use warnings" and the "-
> w" flag. So I guess that if you wanted to enforce the "-w" switch in
> preference to "use warnings", then you would have to do it via a
> shebang line.

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?

OTOH, I think that would only catch compile time warnings. (Don't know
if that's true also for the "-w" switch.)

Conclusion: If you want to enable warnings within a module, "use
warnings" is the preferred way, as long as you don't care about
backwards compatibility with pre 5.6.0 versions of Perl.

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

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