Friday Puzzler: The tag popularity contest

Today’s contest is not only simple, but (hopefully) useful. Write a UDF that will take a string of CFML code as input. The UDF will parse the string for CFML tags. It will then return a result set that includes each tag used (without arguments) and the number of times it is used. This could create a report that looks like so:

<cfset> 9
<cfoutput> 4

Just to be clear, you don’t need to worry about the attributes. Just determine the tags and how many times they were used.

For extra credit, check the string passed in and see if it is a directory. If it is, do a recursive list to get all CFMs and then parse all of those files.

For super extra credit (let’s call em Ray Points), make your script handle custom tags correctly, including knowing that cfmodule template=”ray.cfm” is the same (potentially) as cf_ray.

By the way, can you guess what the top used tags will be? Ben has talked about this many times in the past.

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 https://www.raymondcamden.com

Comments