in reply to split chars in string

try
split'[\w|\W]';
Add codes if missing
or
my @array; for(0..$#string){ my $i = $_; push @array,substr($string,$1,1); }

Replies are listed 'Best First'.
Re^2: split chars in string
by dsheroh (Monsignor) on Nov 23, 2009 at 10:46 UTC
    I'm not sure why you would want to split on word or non-word characters ([\w|\W]) instead of on an empty string:
    $ perl -e 'print "$_\n" for split "", "foo"' f o o
    But, as GrandFather already pointed out, if you think you want to process a string character-by-character in Perl, then the odds are pretty good that you're doing it wrong.
Re^2: split chars in string
by ikegami (Patriarch) on Nov 23, 2009 at 17:57 UTC
    You're mixing two concepts together. When you said
    split /[\w|\W]/

    you meant

    split /[\w\W]/

    or

    split /\w|\W/

    The above would be better written as

    split /./s

    That said, it doesn't work. If you want to separate every character, the characters aren't the separators, the nothings between each character are. You want:

    split //, $x

    The following would also do:

    $x =~ /./sg