"Tore Aursand" <> wrote in message
news

...
> On Mon, 20 Sep 2004 14:13:07 -0500, LHradowy wrote:
> > I have file that looks like this...
> > 1555002 00 0 04 27 TELN NOT
BILL
> > 3555007 00 0 06 00 CUSTOMER
HAS
> >> 1
> > 5555410 00 0 12 10 CUSTOMER
HAS
> >> 1
> > 6755012 00 0 12 06 CUSTOMER
HAS
> >> 1
> >
> > Notice the white spaces at beginning of the line, I DONT WANT THEM THERE
> > Notice the white spaces in the 2nd and 3rd columns, I NEED THEM THERE...
> >
> > I need to created a perl script that takes this file and makes it look
like
> > this
> > 1555002,00 0 04 27,TELN NOT BILL
> > 3555007,00 0 06 00,CUSTOMER HAS > 1
> > 5555410,00 0 12 10,CUSTOMER HAS > 1
> > 6755012,00 0 12 06,CUSTOMER HAS > 1
>
> If we skip everything that has got to do with the file(s), here's a
> suggestion (untested);
>
> while ( <DATA> ) {
> chomp; # Get rid of line breaks
> s,^\s+,,; # Remove leading spaces
> my @cols = split( /\s+{2,}/, $_ ); # Split on two (or more) spaces
> print join( ',', @cols ) . "\n";
> }
Ahhh, I think I am forgetting something, THIS is exactly what I want!
But I am getting an error when I run it, and my skills at perl are weak.
#!/opt/perl/bin/perl
use strict;
use warnings;
while (<>) {
chomp; # Will remove the leading , or new line
s,^\s+,,; #Remove leading spaces
my @cols=split(/\s+{2,}/,$_); #Split on two (or more) spaces
print join (',',@cols)."\n";
}
user@server$ ./test.pl file
Nested quantifiers in regex; marked by <-- HERE in m/\s+{ <-- HERE 2,}/ at
../test.pl line 10.