Hello fellow monks. I am new to the monastery and would appreciate some help with my code. When compiling my code I am getting the following error: "Use of uninitialized value in join or string at ./palin.pl line 39. I have toyed around with the line in question and nothing has worked for me so far. I am extremely new to Perl and would appreciate some help. The code compiles and runs with warnings turned off, but I am trying to follow best practices and leave it on. Please find my code with this post:
#!/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));
}
I am currently trying to format the post correctly, I apologize for the current format.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.