|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Finding length of a variable in perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|