Greetings all,
Let me preface this post with the fact that I am only answering the question posted... Namely the
' All i need to do is take out the extra "," comma that is appearing in the the field' part. The following code is not as universal or portable as most code should be, but this will work give the example line of input from the original post.
That being said... Here is what I would suggest.
#!/usr/bin/perl -w
use strict;#Always
###the sample line of input
my $line = qq*121212, "Simpson, Bart", springfield*;
###capture all quoted strings and place them in @elms
my @elms = $line =~ /("[^"]*")/g;
###got through the captures you found in the string $line;
for(@elms){
###make two copies for later use
my $original_elm = $_;
my $new_elm = $original_elm;
###clean up time
$new_elm =~ s/[,"]//g;
###replace the old with the new element.
$line =~ s/\Q$original_elm\E/$new_elm/;
}
my @elements = split(/,/,$line);
print "@elements"."\n";
exit;
___OUTPUT___
121212 Simpson Bart springfield
Of course this logic will need to be grouped in such a way as to deal with each line of input.
Not all that elegant but you get the general idea.
Hope that helps.
-injunjoel
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.