Dave's Brain

Browse - programming tips - perl split string into characters

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 is better to use pattern matching to find
something in a string.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: