Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

I need a perl script to make every instance of a repeated word unique

by Renyulb28 (Novice)
on Jan 28, 2011 at 21:32 UTC ( [id://884932]=perlquestion: print w/replies, xml ) Need Help??

Renyulb28 has asked for the wisdom of the Perl Monks concerning the following question:

I have a column of ID's that go by the format of 'rs#####', but occasionally I get 'rsundefined' if that ID is missing. In order to do the analyses I desire every ID must be unique, which means that it reads all of the ID's 'rsundefined' as duplicate entries. Thus, I need sort of a find and replace script, except everything it find the word undefined I would like it to add on a different integer to the end of it (ie rsundefined1, rsundefined2, etc etc) so that every ID is unique. Thanks for any help.
  • Comment on I need a perl script to make every instance of a repeated word unique

Replies are listed 'Best First'.
Re: I need a perl script to make every instance of a repeated word unique
by GrandFather (Saint) on Jan 28, 2011 at 22:23 UTC
    I would like it to add on a different integer to the end

    So do that. As you haven't shown us any code or data what further advice are you expecting? What is the problem you are having implementing the "search and replace script"? What have you tried?

    True laziness is hard work
Re: I need a perl script to make every instance of a repeated word unique
by tilly (Archbishop) on Jan 28, 2011 at 23:57 UTC
    The substitution that you will need is s/\bundefined\b/"undefined" . ++$count/eg.

    perlop has instructions for how to use such substitutions (look for "s/PATTERN/REPLACEMENT"), and perlrun documents the -p and -e flags which are likely to prove very useful for you.

Re: I need a perl script to make every instance of a repeated word unique
by biohisham (Priest) on Jan 29, 2011 at 17:50 UTC
    From 'rs#####' I suspect you're dealing with biology-related stuff, what is the file format if any, better still, show how the template looks like and how you want your output looking like, show your attempts, and then it will only be possible to provide you better guidance. The key is, clearly worded question with efforts displayed yield more accurate responses from the generous monks out here..

    Go through How do I post a question effectively? and Perl and Bioinformatics ...


    Excellence is an Endeavor of Persistence. A Year-Old Monk :D .
Re: I need a perl script to make every instance of a repeated word unique
by jeffa (Bishop) on Jan 28, 2011 at 21:37 UTC

    If the ID is missing, then maybe you should not insert it into your table. I presume you are talking about a database here ...are you? Another alternative would be to add an auto incremented column and let your database insert the unique IDs for you.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      While the ID is missing, each entry is still important to keep in the file since it is a reference file associated with another data file. Thus, the analysis program will read the undefined ID as missing, but it still needs it there to keep the two files consistent. I have the reference file as a text file right now with tab delimited formate, and would like to know if there is a simple solution to making each rsundefined unique as that would solve the problem by itself

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found