in reply to Regex refresher

Unless your text is especially irregular (and spaces are missing between some of the elements), it seems to me that you could just say:
print join(",",split(/\s+/,$line,7)),"\n";
If you only wanted the first three elements:
print join(",",+(split(/\s+/,$line,4))[0 .. 2]),"\n";
There doesn't seem to be a need for more complex regular expressions unless you're attempting to validate the data or the delimiting spaces are missing sometimes.

Replies are listed 'Best First'.
Re^2: Regex refresher
by xicheng (Sexton) on Mar 22, 2007 at 16:20 UTC
    Another way to do this(since you are asking for a regex solution)

    $line =~ s/(\s+)/my $n++ < 6 ? ',': $1/eg;

    not very efficient though..