Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to split a string based on character(s) length

by ikegami (Pope)
on Aug 13, 2014 at 16:31 UTC ( #1097310=note: print w/ replies, xml ) Need Help??


in reply to How to split a string based on the length of a sequence of characters within the string

The first argument to split should define what separates the items you want to extract. Wrong tool. You want a vanilla regex match.

my @chunks = $input =~ /(.{1,10})/g;


Comment on Re: How to split a string based on character(s) length
Select or Download Code
Re^2: How to split a string based on character(s) length
by thanos1983 (Pilgrim) on Aug 13, 2014 at 20:19 UTC

    Hello ikegami,

    Your code works perfectly also. By the way I never though to right the code like this my @chunks = $input =~ /(.{1,10})/g;. I did not imagine that can work the array equal to the string straight. Thanks for the tip and for your time to assist me with my question.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      I'm not sure what you mean by that.
      $input =~ /(.{1,10})/g
      returns a list of strings just like
      unpack("(A10)*", $input)
      does. (In list context, of course.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-12-22 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls