How to gvie data type to particular variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raghavendrap
    New Member
    • Oct 2008
    • 19

    #1

    How to gvie data type to particular variable

    Hello friends,
    I am new to perl ,How to give data types to particular variable:
    For example:
    If x is a scalar variable of type signed integer or unsigned interger how to represent it?


    Thanks
    Raghavendra
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    Originally posted by raghavendrap
    Hello friends,
    I am new to perl ,How to give data types to particular variable:
    For example:
    If x is a scalar variable of type signed integer or unsigned interger how to represent it?


    Thanks
    Raghavendra
    There is no need of declaring datatype in Perl. The datatype will be automatically defined while assigning values. e.g. you can define
    Code:
    $a=12;
    $b="This is a line";
    $c='a';
    $d= 12.4567;
    without the need of declaring them as int, string, char or float.

    Comment

    • raghavendrap
      New Member
      • Oct 2008
      • 19

      #3
      Thanx alot,
      my question is how to differentiate signed & unsgined? & how to generate random negative vlues of 32 bit integer.

      Thanks
      Raghavendra

      Comment

      • nithinpes
        Recognized Expert Contributor
        • Dec 2007
        • 410

        #4
        Originally posted by raghavendrap
        Thanx alot,
        my question is how to differentiate signed & unsgined? & how to generate random negative vlues of 32 bit integer.

        Thanks
        Raghavendra
        In Perl, there are only three basic datatypes- scalars, arrays and hashes. So, a variable $x can be used to assign a signed or unsigned integer or both in a script. Both signed and unsigned integers will be considered as scalar datatype. Please clarify, if your question is different.

        To generate random negative values of 32 bit integer, you may use the following approach:

        Code:
        $range = 2**31; # 2^(n-1): n=32
        $min = -2**31; #lowest integer
        $val= int(rand($range)) + $min;
        print "$val\n";
        - Nithin

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by nithinpes
          In Perl, there are only three basic datatypes- scalars, arrays and hashes. So, a variable $x can be used to assign a signed or unsigned integer or both in a script. Both signed and unsigned integers will be considered as scalar datatype. Please clarify, if your question is different.

          To generate random negative values of 32 bit integer, you may use the following approach:

          Code:
          $range = 2**31; # 2^(n-1): n=32
          $min = -2**31; #lowest integer
          $val= int(rand($range)) + $min;
          print "$val\n";
          - Nithin
          I have to agree with nithinpes. You have to remember, Perl isn't C. Some things are just handled.

          Comment

          • raghavendrap
            New Member
            • Oct 2008
            • 19

            #6
            Originally posted by numberwhun
            I have to agree with nithinpes. You have to remember, Perl isn't C. Some things are just handled.
            Yes i got it Nithin, Thank you very much.


            -Raghavendra

            Comment

            Working...