Mega Code Archive

 
Categories / Perl / Array
 

Loop through the array and replace every undefined value with an actual value

for ( $i = 0; $i < 4; ++$i ) {    # if the element is not defined, assign it a value    if ( ! defined( $array[ $i ] ) ) {       $array[ $i ] = "happy";    } } print "@array\n"; print @array, "\n";