Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] defind variable

Expand Messages
  • Arun Pandey
    I think the problem lies with your subroutine randomelement(), Thats because rand @array might be giving you a fractional index, instead of an integer index,
    Message 1 of 5 , Jul 9, 2007
    • 0 Attachment
      I think the problem lies with your subroutine randomelement(),
      Thats because rand @array might be giving you a fractional index, instead of an integer index, so you might want to use an expression something like
      int (rand @array)
      ----- Original Message -----
      From: elavazhagan perl
      To: perl-beginner@yahoogroups.com
      Sent: Saturday, July 07, 2007 11:27 AM
      Subject: [PBML] defind variable


      Hia

      I got the diagnostic msg as follows while executing the
      mutate.pl.Kindlysuggest me how definding some of the variables will
      solve this error.......

      Use of uninitialized value in substr at mutate.pl line 31, <STDIN> line 1.

      Thanks.

      E.Elavazhagan

      ----------------------------------------------------------

      #!/usr/bin/perl
      use strict;
      use warnings;
      print " Enter the DNA Sequences";
      my $DNA;
      my @nucleotide;

      chomp($DNA = <STDIN>);
      my $i;
      my $mutant;
      srand(time|$$);
      $mutant=mutate($DNA);
      print "Mutate DNA\n\n";
      print " Here is the original DNA\n\n";
      print "$DNA\n";
      print "Here is the mutant DNA \n\n";
      print "$mutant\n\n";
      print "Here are 10 successive mutations\n\n";
      for ( $i=0;$i<=10;++$i)
      {
      $mutant=mutate($mutant);

      print ("$mutant\n\n");
      }
      exit;

      sub mutate {
      my ($DNA) =@_;
      my ($position)=randomposition($DNA);
      my ($newbase)=randomnucleotide();
      substr($DNA,$position,1,$newbase);
      return $DNA;
      }
      sub randomposition {
      my($string)=@_;
      return int rand length $string;
      }
      sub randomelement {
      my(@array)= @_;
      return $array[rand @array];
      }
      sub randomnucleotide {
      my ($nucleotides) = ('A','G','C','T');
      return randomelement(@nucleotide);
      }

      [Non-text portions of this message have been removed]




      "Legal Disclaimer: This electronic message and all contents contain information from Cybage Software Private Limited which may be privileged, confidential, or otherwise protected from disclosure. The information is intended to be for the addressee(s) only. If you are not an addressee, any disclosure, copy, distribution, or use of the contents of this message is strictly prohibited. If you have received this electronic message in error please notify the sender by reply e-mail to and destroy the original message and all copies. Cybage has taken every reasonable precaution to minimize the risk of malicious content in the mail, but is not liable for any damage you may sustain as a result of any malicious content in this e-mail. You should carry out your own malicious content checks before opening the e-mail or attachment."
      www.cybage.com




      [Non-text portions of this message have been removed]
    • aditi gupta
      Hello All: I have an array, @array = (0, undef, 2, undef); And I want different operations on numerical and undef array elements. Since numerically undef
      Message 2 of 5 , Jul 9, 2007
      • 0 Attachment
        Hello All:

        I have an array, @array = (0, undef, 2, undef);
        And I want different operations on numerical and undef array elements.

        Since numerically undef behaves as zero, but undef are strings of length zero, I did the following to distinguish between the two:

        $len = length($array[$i]) # where $i-> 0 - 3
        if ($len)
        {
        # the array element is numerical
        }
        else
        {
        # the array element is undef
        }

        This works. However, this also returns the warning (though expectedly):
        "Use of initialized value in length at line..."

        Is there a better way to do so?

        Thank You!

        Aditi


        ---------------------------------
        Download prohibited? No problem. CHAT from any browser, without download.

        [Non-text portions of this message have been removed]
      • a_z0_9_blah
        ... elements. ... Maybe something like this: for (@array[0..3]) { if (defined) { ...do whatever } else { ...$_ is undefined } } Chris
        Message 3 of 5 , Jul 9, 2007
        • 0 Attachment
          --- In perl-beginner@yahoogroups.com, aditi gupta <aditi9783@...>
          wrote:
          >
          >
          > Hello All:
          >
          > I have an array, @array = (0, undef, 2, undef);
          > And I want different operations on numerical and undef array
          elements.
          >
          > Since numerically undef behaves as zero, but undef are strings of
          length zero, I did the following to distinguish between the two:
          >
          > $len = length($array[$i]) # where $i-> 0 - 3
          > if ($len)
          > {
          > # the array element is numerical
          > }
          > else
          > {
          > # the array element is undef
          > }
          >
          > This works. However, this also returns the warning (though
          expectedly):
          > "Use of initialized value in length at line..."
          >
          > Is there a better way to do so?
          >
          > Thank You!
          >
          > Aditi

          Maybe something like this:

          for (@array[0..3]) {
          if (defined) {
          ...do whatever
          }
          else {
          ...$_ is undefined
          }
          }

          Chris
        • Jenda Krynicky
          To: perl-beginner@yahoogroups.com From: aditi gupta Date sent: Mon, 9 Jul 2007 21:34:17 +0100 (BST)
          Message 4 of 5 , Jul 9, 2007
          • 0 Attachment
            To: perl-beginner@yahoogroups.com
            From: aditi gupta <aditi9783@...>
            Date sent: Mon, 9 Jul 2007 21:34:17 +0100 (BST)
            Subject: [PBML] Can zero and undef be distinguished?
            Send reply to: perl-beginner@yahoogroups.com

            >
            > Hello All:
            >
            > I have an array, @array = (0, undef, 2, undef);
            > And I want different operations on numerical and undef array elements.

            perldoc -f defined

            Jenda
            ===== Jenda@... === http://Jenda.Krynicky.cz =====
            When it comes to wine, women and song, wizards are allowed
            to get drunk and croon as much as they like.
            -- Terry Pratchett in Sourcery
          • aditi gupta
            Thank You Chris and Jenda!! :) Jenda Krynicky wrote: To: perl-beginner@yahoogroups.com From:
            Message 5 of 5 , Jul 9, 2007
            • 0 Attachment
              Thank You Chris and Jenda!! :)

              Jenda Krynicky <Jenda@...> wrote: To: perl-beginner@yahoogroups.com
              From: aditi gupta <aditi9783@...>
              Date sent: Mon, 9 Jul 2007 21:34:17 +0100 (BST)
              Subject: [PBML] Can zero and undef be distinguished?
              Send reply to: perl-beginner@yahoogroups.com

              >
              > Hello All:
              >
              > I have an array, @array = (0, undef, 2, undef);
              > And I want different operations on numerical and undef array elements.

              perldoc -f defined

              Jenda
              ===== Jenda@... === http://Jenda.Krynicky.cz =====
              When it comes to wine, women and song, wizards are allowed
              to get drunk and croon as much as they like.
              -- Terry Pratchett in Sourcery






              ---------------------------------
              Here’s a new way to find what you're looking for - Yahoo! Answers

              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.