in reply to A regex question...

yet another way to do it:
use strict; use warnings; my $string= "012345678901234567890123456789"; $string = sprintf "%5s-%5s-%5s<br>%5s-%5s-%5s",$string=~/(\d{5})/g; print $string,$/;

update: I saw Tie::Cycle earlier in this node so you could also do it this way:

use strict; use warnings; use Tie::Cycle; tie my $cycle, 'Tie::Cycle', [ qw( - - <br> ) ]; my $string= "012345678901234567890123456789"; $string =~ s/(\d{5})(?!\b)/$1$cycle/g; print $string;
-enlil

Replies are listed 'Best First'.
Re: Re: A regex question...
by thezip (Vicar) on May 05, 2003 at 19:28 UTC

    Enlil,

    I'd have to say that I like your first solution best of all because it's concise and make it obvious what's going on. I think it will make maintenance easier later on for other folks...

    This is the one-liner I was looking for.

    Enlil++

    Thanks to all who helped!

    Where do you want *them* to go today?