The replacement of commas with vertical bars can be done much more easily:
(you can look up the "tr///" operator in the perlop manpage) Note that you are already assuming that all commas in each line are field delimiters (i.e. there are no commas that are included within quoted fields, or that are escaped in some way, and should not be interpreted as delimiters) -- also, you are taking for granted that every line will contain the same number of commas and fields. If you're really confident that your input data are consistent with these assumptions, then there's no problem. But be aware that many applications do not have this luxury.while (<IN>) { tr/,/|/; print OUT; }
As for this part of your code:
This makes assumptions about the length of the last field of on each input line. It also appears to always set $string2 to ":\" -- is that your intention? (If so, your code is just obfuscated.)
No way for anyone here to know what $string3 would be, without seeing some of the data. There is almost certainly a better/easier way to accomplish what you're trying to do, but you'll need to post a reply with more info about the data.
In reply to Re: Open file & Strip comma delimiter
by graff
in thread Open file & Strip comma delimiter
by skyler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |