UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old December 15th, 2004, 04:50 PM
yogi27 yogi27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Dallas
Posts: 50 yogi27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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.

Reply With Quote
  #2  
Old December 16th, 2004, 04:36 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
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.

Reply With Quote
  #3  
Old December 16th, 2004, 09:14 AM
yogi27 yogi27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Dallas
Posts: 50 yogi27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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.

Reply With Quote
  #4  
Old December 16th, 2004, 10:33 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Finding length of a variable in perl


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway