Solved

Count number of numbers in line

Posted on 2000-02-26
11
159 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

13 Experts available now in Live!

Get 1:1 Help Now