Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > portable no warnings "uninitialized"

Reply
Thread Tools

portable no warnings "uninitialized"

 
 
DKW
Guest
Posts: n/a
 
      01-10-2005
Hi

I'm writing a script which should be as portable as possible.

The version I'm programming in is v5.6.1
and here I can use the following code:

no warnings "uninitialized";


When I try to use that code on another site, where they have an older
version of perl, it complains about this code
(I can't give you the details 'cause I don't have access to that site
right now)

How can I make it portable, so the script avoid the code:
no warnings "uninitialized";
if it's not available (as in older perl)

(I can live with the "uninitialized"-warnings for the older perl)

tia

 
Reply With Quote
 
 
 
 
Peter Scott
Guest
Posts: n/a
 
      01-10-2005
In article <(E-Mail Removed) .com>,
"DKW" <(E-Mail Removed)> writes:
>Hi
>
>I'm writing a script which should be as portable as possible.
>
>The version I'm programming in is v5.6.1
>and here I can use the following code:
>
>no warnings "uninitialized";
>
>
>When I try to use that code on another site, where they have an older
>version of perl, it complains about this code
>(I can't give you the details 'cause I don't have access to that site
>right now)
>
>How can I make it portable, so the script avoid the code:
>no warnings "uninitialized";


Replace that line with

local $^W = 0;

--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-10-2005
DKW wrote:
> I'm writing a script which should be as portable as possible.
>
> The version I'm programming in is v5.6.1
> and here I can use the following code:
>
> no warnings "uninitialized";
>
> When I try to use that code on another site, where they have an older
> version of perl, it complains about this code
> (I can't give you the details 'cause I don't have access to that site
> right now)
>
> How can I make it portable, so the script avoid the code:
> no warnings "uninitialized";
> if it's not available (as in older perl)


The options I can see are to either fix the code so it doesn't generate
uninitialized warnings, or turn off warnings in the production code (but
keep it enabled during development and maintenance).

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
DKW
Guest
Posts: n/a
 
      01-11-2005
Wouldn't that turn of _all_ warnings locally, not just the
"uninitialized" category?

 
Reply With Quote
 
DKW
Guest
Posts: n/a
 
      01-11-2005

Gunnar Hjalmarsson wrote:
> The options I can see are to either fix the code so it doesn't

generate
> uninitialized warnings, or turn off warnings in the production code

(but
> keep it enabled during development and maintenance).


As I wrote in the first post, I want to turn of _only_ the warning
category "uninitialized",
which seems to be possible with the code:
no warnings "uninitialized";
at least from v5.6.1.

However, this will give an error if you try it in perl versions prior
to 5.6 when the warnings module was introduced.

If I rephrase my question:
Can you at runtime check for existence for a module,
and use (or no) it if it exists?

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-11-2005
DKW wrote:
> Gunnar Hjalmarsson wrote:
>> The options I can see are to either fix the code so it doesn't
>> generate uninitialized warnings, or turn off warnings in the
>> production code (but keep it enabled during development and
>> maintenance).

>
> As I wrote in the first post, I want to turn of _only_ the warning
> category "uninitialized",


I understood that, but I wasn't able to figure out a way to do it if you
want the script to also work with pre 5.6.0 Perl versions.

> If I rephrase my question:
> Can you at runtime check for existence for a module, and use (or no)
> it if it exists?


For an ordinary module you can do e.g.:

BEGIN { eval "use SomeModule" }

but the problem with "warnings" is that it's a pragma whose effect is
set lexically.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Peter Scott
Guest
Posts: n/a
 
      01-11-2005
In article <(E-Mail Removed) .com>,
"DKW" <(E-Mail Removed)> writes:
[In response to my suggestion to insert "local $^W = 0"]
>Wouldn't that turn of _all_ warnings locally, not just the
>"uninitialized" category?


Yes. Selective warnings didn't exist in the perls you're trying
to make this work on.

What you could do instead is set up a handler for $SIG{__WARN__}
and inspect the text before deciding what to do with it. See
perldoc perlvar.

--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      01-11-2005


Gunnar Hjalmarsson wrote:

> DKW wrote:
>
>> Gunnar Hjalmarsson wrote:
>>
>>> The options I can see are to either fix the code so it doesn't
>>> generate uninitialized warnings, or turn off warnings in the
>>> production code (but keep it enabled during development and
>>> maintenance).

>>
>>
>> As I wrote in the first post, I want to turn of _only_ the warning
>> category "uninitialized",

>
>
> I understood that, but I wasn't able to figure out a way to do it if you
> want the script to also work with pre 5.6.0 Perl versions.
>
>> If I rephrase my question:
>> Can you at runtime check for existence for a module, and use (or no)
>> it if it exists?

>
>
> For an ordinary module you can do e.g.:
>
> BEGIN { eval "use SomeModule" }
>
> but the problem with "warnings" is that it's a pragma whose effect is
> set lexically.


That does not prevent the more verbose form from working:

BEGIN {
if ( eval { require warnings; 1 } ) {
warnings->unimport('uninitialized');
}
}

Or even just

BEGIN {
eval {
require warnings;
warnings->unimport('uninitialized');
}
}


 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-11-2005
Brian McCauley wrote:
> Gunnar Hjalmarsson wrote:
>> DKW wrote:
>>> If I rephrase my question:
>>> Can you at runtime check for existence for a module, and use (or no)
>>> it if it exists?

>>
>> For an ordinary module you can do e.g.:
>>
>> BEGIN { eval "use SomeModule" }
>>
>> but the problem with "warnings" is that it's a pragma whose effect is
>> set lexically.

>
> That does not prevent the more verbose form from working:
>
> BEGIN {
> if ( eval { require warnings; 1 } ) {
> warnings->unimport('uninitialized');
> }
> }
>
> Or even just
>
> BEGIN {
> eval {
> require warnings;
> warnings->unimport('uninitialized');
> }
> }


Hmm.. So

no warnings 'uninitialized';

does only affect the current block, while

warnings->unimport('uninitialized');

is more widely applied. Is the latter file scoped or dynamically scoped?
Btw, is it documented anywhere?

Anyway: Thanks, Brian, that should be exactly what the OP is looking for.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
DKW
Guest
Posts: n/a
 
      01-14-2005
Thank you all, guys!

I will try some of these techniques.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Portable Python - free portable development environment ! perica.zivkovic@gmail.com Python 7 01-13-2007 11:19 AM
portable (VHDL) vs. non-portable (altera LPM) approaches to signed computations Eli Bendersky VHDL 1 03-01-2006 02:43 PM
there are too many warnings (you are about to....etc etc forever) after installing Firefox trevor_smithson@yahoo.com Firefox 2 10-13-2005 07:35 PM
use warnings; and use Warnings; give different results Ted Sung Perl Misc 1 08-30-2004 10:22 PM
disabling certain warnings in synopsys dc Tuukka Toivonen VHDL 1 05-11-2004 01:51 PM



Advertisments