Thus, the usual ID of 1293 might be 1293&1295 or 1293&1295&1305. Thus, for this, I would like perl to go through and if it finds a "&" symbol, delete it along with all other strings after it, therefore only leaving the first ID.
print ((split /\&/, $string)[0]);
The second problem is that for the attribute column, it needs to be either 0 for missing, 1 for HCR, or 2 for LCR. Right now the format is either 13HCR-NIH-0 or 13LCR-NIH-0. The numbers in there are arbitrary. What I would like perl to do is if it detects the string "HCR" in a line in column 5, change the entire string to 1, and same for "LCR" and 2. For this I have tried using the find and replace
Unless there's a a reason for doing one-liners (golfing, for a example), I try my best to avoid it.if (scalar(grep/HRC/, $att) > 0) { $var = 1; } elsif (scalar(grep/LRC/, $att) > 0) { $var = 2; } else { $var = 0; }
In reply to Re: Data format - delete parts of string and replace strings that match characters partly with numbers.
by jellisii2
in thread Data format - delete parts of string and replace strings that match characters partly with numbers.
by Renyulb28
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |