Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: regular expression (search and destroy)

by injunjoel (Priest)
on Nov 12, 2003 at 22:46 UTC ( [id://306661]=note: print w/replies, xml ) Need Help??


in reply to regular expression (search and destroy)

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://306661]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-29 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found