Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: how to split the string into two or three numbers based on certain value.

by thundergnat (Deacon)
on Feb 11, 2013 at 20:12 UTC ( #1018233=note: print w/ replies, xml ) Need Help??


in reply to how to split the string into two or three numbers based on certain value.

It's not really clear what you want if you run out of digits and the last number is less than 32. Maybe something like this will work?

use warnings; use strict; my $string = '79899920179'; my @nums; while (length $string){ no warnings qw/uninitialized/; my $num; $num .= substr($string, 0, 1, '') while (length $string and $num < + 32); push @nums, $num; } print join ', ', @nums;
79, 89, 99, 201, 79


Comment on Re: how to split the string into two or three numbers based on certain value.
Download Code
Re^2: how to split the string into two or three numbers based on certain value.
by 7stud (Deacon) on Feb 12, 2013 at 07:08 UTC
    You'll get the same results if you replace 'length $string' with '$string'.
      Except for cases where you will not. Try 9049589370.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Ah yes. The string '0' is considered false in perl despite having a length of 1. So if $str = '0', then $str will be considered false in a boolean context where length($str) will be 1 and evaluate to true.

        I wonder what the op wants to output for the string '0'? Also, I wonder what the output should be for the string '0123'?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-08-30 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls