On Tue, Aug 21, 2007 at 12:47:22AM +1000, Ken Foskey wrote:

> I have a piece of code that I am assured works and I cannot see why it
> would.  Code is supposed to force undefined, zero and all space to
> numeric zero to stop printf being undefined.
> 
> foreach my $value (@array) {
>     if( ! $value or $value = "      " ) {
>         $value = 0;
>     }
> }
> 
> Will this actually work, or as I suspect do nothing because $value is a
> copy.

What happened when you tried it?

I suspect that it set all the values in @array to zero because you used =
instead of eq in your comparison.

> The root cause of the problem is that the array is read from a file with
> a simple substr
> 
>   $array[0] = substr( $_, 256, 6 );
> 
> Despite documented standards some values are simply filled with blanks.
> 
> Then rebuilt with a printf "%06d", $array[0]; and this causes a non
> numeric warning.
> 
> Is there a 'better' way to do this.

Turn off the warning?

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to