Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Count number of numbers in line

Posted on 2000-02-26
11
183 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pattern matching in perl 2 107
How to send output of ping to syslog (with timestamp and optional comments) 3 230
Perl modules on linux ec2 3 114
Perl File::Find alternative 1 78
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

837 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