in reply to working with non-delimited files

You want to know about the /g modifier. Read about it in perldoc perlre:

Update: on a second reading you probably want (code updated to reflect the change):

#!/usr/bin/perl use strict; use warnings; while (my $line=<DATA>) { $line =~ s/\s+/|/ for 1..5; print $line; } __DATA__ This# is stand alone data "but this data needs to , sta +y together/ and here is some more -but this is a single column

Replies are listed 'Best First'.
Re^2: working with non-delimited files
by FunkyMonk (Bishop) on May 24, 2007 at 21:28 UTC
    You've overwritten $_

    Try

    while (my $data = <DATA>) { $data =~ s/\s+/\|/ for 1..5; print $data; }
    Edit: Damn. Too Slow.
      Edit: Damn. Too Slow.

      You're right: I updated my node and said so. Then the update was wrong too, and I made a further update silently, in the hope that no one would notice... ;-) Of course you solution with split is far better, except that even for such a tiny thing I would use while instead of for. Until we're in full Perl 6 times, that is...