----- Original Message ----- From: "Ken Foskey" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: "beginners perl" <beginners@perl.org>
Sent: Monday, August 20, 2007 10:47 AM
Subject: modification



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.

Hello Ken
In a for(or foreach) loop, if $value is changed, the actual array element is changed;
Best described here:
http://perldoc.perl.org/perlsyn.html#Foreach-Loops-for-foreach
Chris

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.

--
Ken Foskey
FOSS developer




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


Reply via email to