Created
November 28, 2011 05:37
-
-
Save numberwhun/1399241 to your computer and use it in GitHub Desktop.
Split a string into its individual characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
######################################################################### | |
# Script: characters.pl | |
# Author: Jefferson Kirkland | |
# Date: December 11, 2007 | |
# | |
# Description: This script takes a phrase, with or without spaces, and | |
# prints it out, one character at a time with each character on its own | |
# line. | |
# | |
# Why does this code work? Here is the explanation from the perldoc | |
# page: | |
# | |
# A pattern matching the null string (not to be confused with a null | |
# pattern // , which is just one member of the set of patterns matching | |
# a null string) will split the value of EXPR into separate characters | |
# at each point it matches that way. | |
# (From: http://perldoc.perl.org/functions/split.html) | |
# | |
# Copyright: Jefferson Kirkland, ParsedContent Solutions | |
######################################################################### | |
my $phrase = "pure flipping magic"; | |
my @array = split(/ */, $phrase); | |
foreach my $char (@array) | |
{ | |
print("$char\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment