in reply to Use of uninitialized value in join or string
This may be a wasted node when OP or the Janitors provide code tags, but (from the xml view) this appears to be what OP was trying:
#!/usr/bin/perl use strict; my @palindromes = (); my @names = qw( Aaron Adam Amir Ann Anna Art Axel Brent Brian Ch +arles Chuck Cris Dave Don Dori Doug Eva Fred Gregor Ia +n Ima Ira Jarl Jason Jay Jeff Joe Joel John Kari Kim K +irk Kris Lar Leo Lex Lin Mara Marc Mark Mary Michael + Mike Miki Mott Naim Nils Nora Norm Omar Pete Raj Ralf + Ram Ramon Rik Rod Roger Ron Tom Tony Tran Travis Sar +ah Palin ); for my $word1 (@names) { for my $word2 (@names) { for my $word3 (@names) { #if ($word1 eq $word2) #next; if ( palin( $word1, $word2, $word3 ) ) { push @palindromes, $word1,'',$word2,'', $word3; print "$word1 $word2 $word3\n"; last; } else { if ( palin( $word1, $word2 ) ) { push @palindromes, $word1,'',$word2; print "$word1 $word2\n"; last; } } } } } sub palin { my $names1 = shift; my $names2 = shift; my $names3 = shift; my $string = join( '',$names1,$names2,$names3); my $reversestring = reverse($string); return ( uc($reversestring) eq uc($string)); }
My take is that OP seeks to generate all possible permutations of the elements of @names two OR three at a time; to test for palindromes in the sub; and (at lines 19 and 25), print those which pass the test.
That may even be correct - :-) - but OP fails to tell us and it seems to me obvious (YMMV) that this code does not accomplish that for reasons well beyond the scope of the warning cited as an "error."
For example, running withOUT -w or use warnings, this produces such non-palindromic strings as:
Ann Ann Anna
Ann Anna
as well as valid output (once spaces are stripped):
...Kirk Rik
Leo Joel
Lex Ann Axel
Lex Axel
Mara Ram...
but skips such apparently acceptable permutations as
Anna Anna Anna
despite the fact that lines 14 and 15, skipping over dups in $words1 and $words2, are commented out.)
All the above leads me to two questions:
Does this interpretation make sense?
and...
Will OP, please, explain the original intent?
It is much easier to offer help -- even if beyond the scope of the question about the "error" -- when we know what you are trying to do. To paraphrase a former US Veep, A node is a terrible thing to waste.
|
|---|
| Replies are listed 'Best First'. |
|---|