467,081 Members | 1,224 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

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
Oct 27 '08 #1
  • viewed: 2487
Share:
5 Replies
nithinpes
Expert 256MB
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
Expand|Select|Wrap|Line Numbers
  1. $a=12;
  2. $b="This is a line";
  3. $c='a';
  4. $d= 12.4567;
  5.  
without the need of declaring them as int, string, char or float.
Oct 27 '08 #2
Thanx alot,
my question is how to differentiate signed & unsgined? & how to generate random negative vlues of 32 bit integer.

Thanks
Raghavendra
Oct 27 '08 #3
nithinpes
Expert 256MB
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:

Expand|Select|Wrap|Line Numbers
  1. $range = 2**31; # 2^(n-1): n=32
  2. $min = -2**31; #lowest integer
  3. $val= int(rand($range)) + $min;
  4. print "$val\n";
  5.  
- Nithin
Oct 27 '08 #4
numberwhun
Expert Mod 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. $range = 2**31; # 2^(n-1): n=32
  2. $min = -2**31; #lowest integer
  3. $val= int(rand($range)) + $min;
  4. print "$val\n";
  5.  
- Nithin
I have to agree with nithinpes. You have to remember, Perl isn't C. Some things are just handled.
Oct 27 '08 #5
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
Oct 29 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by gordy | last post: by
10 posts views Thread by Zap | last post: by
11 posts views Thread by theshowmecanuck | last post: by
5 posts views Thread by Craig | last post: by
5 posts views Thread by Chris | last post: by
11 posts views Thread by Brad Pears | last post: by
10 posts views Thread by John Salerno | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.