Dave's Brain

Browse - Programming Tips - How do I split a string into characters so I can look at each one?

Date: 2011jul7
Language: perl

Q.  How do I split a string into characters so I can look at each one?

A.  Use split() with // as the pattern.  For example:

$str = 'hello'; for $c (split(//,$str)) { print "c=$c\n"; }
However, usually in perl its better to use pattern matching to find something in a string.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.