Solved

Count number of numbers in line

Posted on 2000-02-26
11
168 Views
Last Modified: 2010-03-05
Hello,

How to count the number of numbers in the folling line.

$test = "1232344556";

The result has to be 10!

How to do that!!

greetings Michel
0
Comment
Question by:mmcw
  • 7
  • 4
11 Comments
 
LVL 8

Accepted Solution

by:
shlomoy earned 100 total points
ID: 2562178
$test="1232344556";
$test=~s/(\d)/$1 /g;
## 1 2 3 2 3 4 4 5 5 6
@test=split " ", $test;
$number_of_numbers = @test;
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 2562179
Of course,

$number_of_numbers = length $test;

as well....

(which is a faster way...).
0
 

Author Comment

by:mmcw
ID: 2562199
Not what I do is the
following

example!!

$number_of_numbers = "60";

$number_of_numbers = $number_of_numbers/40;

The result is 1.5

What I now need is that number will be roundoff up.

$number_of_numbers has to become 2.

But this roundoff has to be done not as we normal round off a number, but by the following way!!

0.5 becomes 1
0.2 becomes 1
1.2 becomes 2
4.7 becomes 5
3.02 becomes 4

How to do that!!






0
 
LVL 8

Expert Comment

by:shlomoy
ID: 2562214
That's another question, dude :-)
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 2562216
Do you accept my answer to your question?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mmcw
ID: 2562218
Of course, but can you help me??
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 2562220
Yes, But please post your new question as a seperate one.
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 2562247
for example:
$number=56987658.09728794645;

$number=~m/(\d+)(\.)?(\d+)?/; $number=$1;
if ($2 && $3) {
   $number++ if $3>0;
}
print "$number\n";
0
 

Author Comment

by:mmcw
ID: 2562413
Adjusted points to 100
0
 

Author Comment

by:mmcw
ID: 2562414
I increaded the point to 100!!

Thank you again!!
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 2562417
Welcome.
Ask more questions :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now