December 15th, 2004, 05:50 PM
-
Finding length of a variable in perl
Hi,
I am getting the value of $var by: $var = substr($addr,0,1);
And depending on length of $var, I do some processing:
if ($#var == 1) {
....................
} elsif ($#var == 2) {
....................
}
But, I never go into this if condition even if $var = 7.
Can someone help me with this. Thanks.
-Yogesh.
December 16th, 2004, 05:36 AM
-
yogi27
- may i kindly ask you for a little more precision, what do you want?
- read your code
i am not a perl specialist, i just use use it
the statement: $var = substr($addr,0,1);
IMO, assign to $var the value of $addr starting by pos 0 ending by pos 1
so if $addr is not empty, $var will always be the first char of $addr w/ length == 1
perl sure knows a function (maybe) length() to compute a string length
also: $mylen = length($var);
what are you checking here: if ($#var == 1)
NO SENSE for me.
December 16th, 2004, 10:14 AM
-
This is what I want:
If the length of the variable is 1, I'll append it by 2 zeros. If the length of the variable is 2, I'll append it by 1 zero. If the length of the variable is 3, I'll append it by 0 zeros.
I want to get the value in 3 digits.
Thanks,
Yogesh.
December 16th, 2004, 11:33 AM
-
you are not clear, whats means
>>> If the length of the variable is 1, I'll append it by 2 zeros....
a) var=a; do you want: a00(this appends) or 00a(this inserts) ?
b) is var an int or char ?
c) man pages: printf