develooper Front page | perl.perl5.porters | Postings from June 2011

[perl #9423] vec assignments generate 2 warnings, I'd prefer none

Thread Previous
From:
Alexandr Ciornii via RT
Date:
June 13, 2011 11:53
Subject:
[perl #9423] vec assignments generate 2 warnings, I'd prefer none
Message ID:
rt-3.6.HEAD-16080-1307991206-1410.9423-14-0@perl.org
Same 2 warnings for each line on perl 5.14.0.

http://rt.perl.org/rt3/Ticket/Display.html?id=9423

On Fri May 31 02:26:08 2002, dcd@tc.fluke.com wrote:
> The following script issues warnings (2 of them) for
> vec assignments, while normal assignments to scalars
> don't generate any warnings.  Since perl guarantees that
> the extra bits are filled with zeros, I believe it
> should not issue these warnings.
> 
> While the script demonstrates simple cases, the
> testing if the hash element exists and pre-initializing
> it before the vec assignment complicates production
> scripts, and I'd strongly prefer to avoid "no warnings".
> 
> Use of uninitialized value in vec at vec_warn.pl line 16.
> Use of uninitialized value in scalar assignment at vec_warn.pl line
>    16.
> Use of uninitialized value in vec at vec_warn.pl line 17.
> Use of uninitialized value in scalar assignment at vec_warn.pl line
>    17.
> 
> $ cat vec_warn.pl
> 
> use warnings;
> use strict;
> 
> my ($s, %sh);
> $s = 1;
> $sh{foo} = 1;
> 
> #If an element off the end of
> #the string is written to, Perl will first extend
> #the string with sufficiently many zero bytes.
> # yet perl generates 2 warnings each for the following 2 vec
>    assignments.
> #   Use of uninitialized value in vec
> #   Use of uninitialized value in scalar assignment
> my ($v, %vh);
> vec($v,0,1) = 1;
> vec($vh{foo},0,1) = 1;
> 
> # to avoid warnings must pre-init vectors
> 
> my ($wv, %wvh);
> $wv = $wvh{foo} = '';
> vec($wv,0,1) = 1;
> vec($wvh{foo},0,1) = 1;

-- 
Alexandr Ciornii, http://chorny.net


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About