Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to split an integer??

by tobyink (Canon)
on Dec 06, 2012 at 10:26 UTC ( [id://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'

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found