good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
([\,]) only matches a single non-comma character. It is missing a quantifier such as + or *. Everytime I see (.*) I feel very uneasy, and usually I can think of a much simpler way to accomplish the same thing. In this case, all the regular expression is really doing is finding the first comma! Now, split normally splits on all the delimiters it finds in a string, but it can take an optional third argument which tells it exactly how much to split the line; in this case we just want two fields. As a bonus we can give the split fields names so we don't have to use $1 and $2.
Another thing that would make me think twice about your solution is that you've got an if statement, but there's no sensible behaviour defined for when the if is false! Although I have to say that using a proper CSV module (Text::CSV, etc) is always preferable.
In reply to Re^2: CSV file
by integral
|
|