Friday Puzzler : Lines, your days are numbered...

Ok, that's kind of a dumb title. Todays puzzler could actually be a nice little utility. In fact, the winner will get added to CFLib, so this isn't a total waste of a time. A few days ago I discovered the nl command. It takes a file and dumps it out to the screen with line numbers. Very handy! Your job is to build a UDF that will:

a) Take a filename or string as input. b) Return a string that contains the contents of the file with a line number at the beginning of each line.

Bonus points if you format it such that the line #s 1-9 have a space in them if the total number of lines is greater than 10. This isn't as easy as it sounds. There may be 1000, or 10000 lines. This would change the amount of padding needed.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA