Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to split an integer??

by tobyink (Abbot)
on Dec 06, 2012 at 10:26 UTC ( #1007518=note: print w/ replies, xml ) Need Help??


in reply to How to split an integer??

Looks very similar to this question: Manipulating data from a file.

See my previous answer: Re: Manipulating data from a file.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: How to split an integer??
Re^2: How to split an integer??
by nvivek (Vicar) on Dec 06, 2012 at 10:32 UTC
    We can also do it in simple manner by using numeric operator for comparison without having regular expression used in the mentioned thread.

      I prefer the regular expression to numeric comparison, because...

      use strict; my $var = "xyz"; print "it's a single-digit number!!\n" if $var < 10;

      Is "xyz" really a single digit number?

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        But my qn is i have a variable say $a= 23 , now i need to add it as 2+3 which should give me ans 5 ... hw to do this ???

        23 s stored as a single byte hence i cant split. But in words we can split character by character of a word in an array

        my @a = qw (data); foreach $aa(@a){ print $aa."\n"; }

        the above code will not work the sane for integers

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-07-05 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls