in reply to Strange "undefined value as an ARRAY reference" error

Replies are listed 'Best First'.
Re^2: Strange "undefined value as an ARRAY reference" error
by ikegami (Patriarch) on Jan 08, 2009 at 02:58 UTC

    I'd try

    sub ikegami1 { my ($ref, @wordsCopy) = @words; while, ($ref =~ /(.)/g) { my $letter = $1; my $pos = $-[0]; for ( @wordsCopy ) { if ( substr( $_, $pos, 1 ) ne $letter ) { substr( $ref, $pos, 1, '-' ); last; } } } return $ref; } sub ikegami2 { my ($ref, @wordsCopy) = @words; for my $pos (0..length($ref)) { my $letter = substr( $ref, $pos, 1 ); for ( @wordsCopy ) { if ( substr( $_, $pos, 1 ) ne $letter ) { substr( $ref, $pos, 1, '-' ); last; } } } return $rv; } sub ikegami3 { my @wordsCopy; push @wordsCopy, [ /./g ] for @words; my $ref = pop(@wordsCopy); for my $pos (0..$#$ref) { my $letter = $ref->[$pos]; for ( @wordsCopy ) { if ( $_->[$pos] ne $letter ) { $ref->[$pos] = '-'; last; } } } return join '', @$ref; }

    These are just attempted improvements on your method. It's not going to beat the bit method.

Re^2: Strange "undefined value as an ARRAY reference" error
by MidLifeXis (Monsignor) on Jan 08, 2009 at 17:42 UTC

    A little humor

    What's with the use of $bolean? Aside from the fact that it should be spelled "boolean"

    I think it is pronounced b-oh-l-ee-n (rhymes with Go Lean). It is a breakfast cereal consumed in Hazard County.

    and yes, it is very little humor ;-)

    --MidLifeXis