http://www.perlmonks.org?node_id=1007518


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'

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