There's probably better/more efficient ways to do this, but this might do what you are asking. I'm not sure because your question isn't real clear.
This snippet will tab delimit the data after replacing the comma's and truncating the end spaces in the second (pos 15-25) field. In the future it is in your best interest to provide a clearer explaination and an exact representation of the data you want to parse. People will help you here, but you need to do your part also.
#!/usr/local/bin/perl -w
use strict;
my @data = ('client-up-to-,Doe,Smith , Inc, jwaters,pfloyd,jjoplin');
foreach my $line (@data) {
chomp $line;
my $beg_line = substr($line, 0, 14);
my $name_field = substr($line, 14, 10);
my $end_line = substr($line, 25);
print "B: ~$name_field~\n";
$name_field =~ tr/,/ /;
$name_field =~ s/\s*$//;
print "A: ~$name_field~\n";
$line = "${beg_line}${name_field}${end_line}";
$line =~ tr/,/\t/;
print "~$line~\n";
}
__END__
B: ~Doe,Smith ~ #note space is still in at this point
A: ~Doe Smith~
~client-up-to- Doe Smith Inc jwaters pfloyd jjoplin~
-THRAK
www.polarlava.com
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.