Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Palindrome array

by Jim (Curate)
on Dec 29, 2012 at 09:01 UTC ( #1010804=note: print w/ replies, xml ) Need Help??


in reply to Palindrome array

This isn't C. In Perl, a palindrome is properly represented as a string, not an array of characters.

#!perl use strict; use warnings; my $string = "A Man, A Plan, A Canal -- Panama!"; my $letters = lc $string; $letters =~ s/\W//g; printf qq/"%s" %s a palindrome.\n/, $string, $letters eq reverse($letters) ? "is" : "isn't"; __END__ "A Man, A Plan, A Canal -- Panama!" is a palindrome.

If this is a homework assignment, tell your teacher you expect to be given more verisimilar programming problems. ;-)

If you're writing a Perl program to identify palindromic sequences in nucleic acids, you should still use strings, not arrays of characters, in my opinion.

Jim


Comment on Re: Palindrome array
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2015-07-02 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls