Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Counting characters in a string

by valentin (Abbot)
on Feb 06, 2004 at 14:40 UTC ( #327084=note: print w/replies, xml ) Need Help??

in reply to Counting characters in a string

print map { "$_\n" } $string =~ /.{1,5}/g;

Replies are listed 'Best First'.
Re: Re: Counting characters in a string
by ysth (Canon) on Feb 06, 2004 at 16:02 UTC
    That will stop at every newline and continue again after it:
    $ perl -we'$string = "abcdef\nghijk\nlmno\npqr\nst\nu"; > print map { "$_\n" } $string =~ /.{1,5}/g;' abcde f ghijk lmno pqr st u
    You either want the //s flag on the match or some other way of dealing with newlines.
      thanks, you are right //s is fine for me.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2016-10-26 22:06 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (350 votes). Check out past polls.