Re: Convert a string into array of characters
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 04:44:17 GMT
A. Sinan Unur wrote:
usenet@xxxxxxxxxxxxxxx wrote in news:1141074920.245948.5590
@i39g2000cwa.googlegroups.com:
I can do this to convert a scalar string into an array of individual
characters:
my @characters = split (undef, $string); #or ('', $string)
But if I get close to my screen, I detect a faint odor of bad code. Is
there a better way?
Is there something you want to apply to each character in return?
Would iterating over each character be acceptable?
#!/usr/bin/perl
use warnings;
use strict;
my $foo = 'ffooooo';
do_something($1) while $foo =~ m{(.)}g;
To be equivalent you would have to include the /s option:
do_something($1) while $foo =~ m{(.)}sg;
And you don't really need the capturing parentheses:
do_something($_) for $foo =~ m{.}sg;
John
--
use Perl;
program
fulfillment
.
- References:
- Convert a string into array of characters
- From: usenet
- Re: Convert a string into array of characters
- From: A. Sinan Unur
- Convert a string into array of characters
- Prev by Date: Re: Import other perl files
- Next by Date: Re: References as Hash Keys, Tree Structures (Newbie)
- Previous by thread: Re: Convert a string into array of characters
- Next by thread: Re: Convert a string into array of characters
- Index(es):
Relevant Pages
|
|