Perl: if you chomp() to split(), skip the first
In Perl it is common to write a readline() while loop over a file to read its content in memory.
When the file contains tab-separated data, many use chomp() to remove the newline from each input line and then split(/\t/) to separate the values into an array.
Today, trying to improve the performances of one program I wrote, I discovered that I was spending the same amount of time on both functions. Eliminating one of them would have doubled the speed of my code.
If your input data do not contain spaces, you can skip the chomp() and use split(/\s+/) or use split(/[\t\n]/) if it does.
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.
