compare array element

Discussion in 'Perl Misc' started by Rose, Feb 22, 2008.

  1. Rose

    Rose Guest

    I find the following codes will give match for 'C' to '-', what's the
    problem?

    $preseq = "C-";
    @preseq = splilt '', $preseq;

    $curseq = "--";
    @curseq = splilt '', $curseq;

    $len = @curseq;
    $len--;

    if ($preseq[$len-1] == $curseq[$len-1]) {
    print "P:$preseq[$len-1]\n";
    print "C:$curseq[$len-1]\n";
    }
    Rose, Feb 22, 2008
    #1
    1. Advertising

  2. Rose wrote:
    > I find the following codes will give match for 'C' to '-', what's the
    > problem?
    >
    > $preseq = "C-";
    > @preseq = splilt '', $preseq;
    >
    > $curseq = "--";
    > @curseq = splilt '', $curseq;
    >
    > $len = @curseq;
    > $len--;
    >
    > if ($preseq[$len-1] == $curseq[$len-1]) {
    > print "P:$preseq[$len-1]\n";
    > print "C:$curseq[$len-1]\n";
    > }


    The problem is that you ask for help with debugging, while you haven't
    first asked Perl for help by using strictures and warnings.

    Add

    use strict;
    use warnings;

    to the beginning of the script, and make the adjustments needed to get
    rid of possible error and warning messages.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 22, 2008
    #2
    1. Advertising

  3. Rose

    Rose Guest

    Thanks to both Bob Walton's explanation and Gunnar Hjalmarsson's critics. I
    feel very sorry for raising such stupid questions although I am very
    hopeless to be ordered to learn several languages at the same time. I will
    pay more attention to use strict and use warnings next time
    Rose, Feb 22, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HANM
    Replies:
    2
    Views:
    695
    Joseph Kesselman
    Jan 29, 2008
  2. Szabolcs Borsanyi
    Replies:
    6
    Views:
    651
    Ben Bacarisse
    May 23, 2008
  3. Al Cholic
    Replies:
    18
    Views:
    263
    Al Cholic
    Jul 28, 2007
  4. Greg Ma
    Replies:
    7
    Views:
    156
    Robert Klemme
    Feb 15, 2010
  5. Davy

    Can I compare array with array?

    Davy, Jul 16, 2006, in forum: Perl Misc
    Replies:
    12
    Views:
    151
    Charles DeRykus
    Jul 17, 2006
Loading...

Share This Page