Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

how to split full digit number?

by virudinesh (Acolyte)
on May 06, 2013 at 11:09 UTC ( #1032246=perlquestion: print w/ replies, xml ) Need Help??
virudinesh has asked for the wisdom of the Perl Monks concerning the following question:

my coding is #!/usr/bin/perl use warnings; use strict; my $f = 'chap 89.9'; if($f=~m/chap.( |[a-z])*(\d+)/i) { print " $2 \n"; } 1.its print only 89 out put : *..print full digit number 89.9 * also need n number of digit number

Comment on how to split full digit number?
Download Code
Re: how to split full digit number?
by hdb (Prior) on May 06, 2013 at 11:24 UTC

    See below. I have added an extra pair of parantheses to make .9 optional...

    use warnings; use strict; my $f = 'chap 89.9'; if($f=~m/chap.( |[a-z])*(\d+)(\.(\d+))?/i) { print " $2 $4\n"; }
Re: how to split full digit number?
by Anonymous Monk on May 06, 2013 at 12:48 UTC

    simply like so:

    #!/usr/bin/perl use warnings; use strict; my $f = 'chap 89.9'; if($f=~m/chap\s+?(\S+)/) { print " $1 \n", scalar @{[split//,$1]} -1; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032246]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-11-26 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls