in reply to Simple search and replace trouble!!
Use Text::CVS to do the heavy lifting:
#!/usr/bin/perl -w use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new(); while (defined (my $line = <DATA>)) { next if ! $csv->parse ($line); my @fields = $csv->fields(); $fields[2] = join ' ', reverse split /,\s*/, $fields[2]; $csv->print (*STDOUT, \@fields); print "\n"; } __DATA__ -###.####,##.###,"Doe, John & Jane","### Main St","Town, State 13370", +,, -###.####,##.###,"Doe, John","### Main St","Town, State 13370",,,
Prints:
-###.####,##.###,"John & Jane Doe","### Main St","Town, State 13370",, +, -###.####,##.###,"John Doe","### Main St","Town, State 13370",,,
Note that there was a missing " in the second line of the sample data which I presume was a typo. If it wasn't a typo you've got a bigger problem - your data is corrupt!
|
|---|