in reply to Splitting a string

Hi,
I do not understand the second part of your question, but for the first part (the splitting), you could do it like this:
#!/usr/bin/perl use strict; use warnings; my $string="perl monks"; $string =~ s/\s//; my @splitted_string; my @chars=split(//, $string); for ($i=0;$i<=$#chars;$i++) { push (@splitted_string, $chars[$i].$chars[$i+1]); } my $splitted_string = join(' ', @splitted_string);

Regards,
svenXY

Replies are listed 'Best First'.
Re^2: Splitting a string
by ikegami (Patriarch) on Feb 08, 2006 at 17:26 UTC
    • Your code doesn't compile due to a strict error.
    • Your code gives a warning (once the strict error is fixed).
    • Your code doesn't give the right output. (lm shouldn't appear.)