in reply to Best way to put : between fields in a string

Special variables to the rescue:

Using $,

my $s = 'A3xyz45M98AB7Z9'; local $, = ":"; print split /(?<=\d)(?=\D)/, $s;

Using $"

my $s = 'A3xyz45M98AB7Z9'; local $" = ":"; print "@{[split /(?<=\d)(?=\D)/, $s]}";

Replies are listed 'Best First'.
Re^2: Best way to put : between fields in a string
by cog (Parson) on Apr 21, 2005 at 12:02 UTC
    Using $;

    my $s = 'A3xyz45M98AB7Z9'; my $i = 0; %_ = map { (++$i, $_) } split /(?<=\d)(?=\D)/, $s; local $; = ":"; $_{ (), map { delete $_{$_} } 1..$i }=0; print keys %_;

    Couldn't help myself O:-) Sorry :-)