Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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'

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
Node Status?
node history
Node Type: note [id://1007518]
help
Chatterbox?
[Corion]: Yeah, you need bool to get a true value, and the rest to return the other value ;)
[choroba]: perl -wE '{package o; use Tie::Scalar; use parent -norequire => "Tie::StdScalar" ;sub FETCH { "x" x int rand 2}} tie my $x, "o" ; say $x for 1 .. 10'
[choroba]: for complete ness

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2017-07-27 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (414 votes). Check out past polls.