Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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??
Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2015-10-04 21:18 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (105 votes), past polls