So elegant means: without branching, instantiation, or mappings? I wonder what an elegant application would look like then. Would all the code be in one giant template? ;)
My component would look quite different than that. I wasn't attempting to provide the code, just the idea, because I was confused/shocked at what the community was proposing. No I'm not a manager and I wasn't picking on your code specifically. I just grabbed the latest email. Let's hear back from the others. -Daniel Elmore -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marlon Moyer Sent: Wednesday, September 13, 2006 8:59 PM To: Dallas/Fort Worth ColdFusion User Group Mailing List Subject: Re: [DFW CFUG] Brain Teaser Yes, this is my idea of elegant. It's self contained, doesn't take up much space, and functions correctly and quickly without a lot of branching, instantiation, or mappings, etc. What you described below is a good, simplified flow of the overall process. Unfortunately you left off the implementation. Are you by chance a manager? <cfcomponent hint="I am a url object and provide related functionality for parsing different parts of urls"> <cfset variables.instance = structnew()/> <cfset variables.instance.the_url = ""/> <cffunction name="init"> <cfargument name="the_url" type="string" required="true"/> <cfset variables.instance.the_url = arguments.the_url/ > <cfreturn this/> </cffunction> <cffunction name="getVar" returntype="string"> <cfargument name="var_name" required="true"/> <cfset var the_value = ""/> <cftry> <cfset the_value = listgetat(rereplace(variables.instance.the_url,"[(?|&)]*pageNum=(\d*)","#chr (10)#\1#chr(10)#","all"),2,"#chr(10)#")> <cfcatch type="any"> <!--- The variable must not have been in the url ---> <cfset the_value = ""/> </cfcatch> <cfreturn the_value/> </cffunction> </cfcomponent> USAGE: <cfset objURL = createObject("components.url_manager").init(cgi.http_referer)/> <cfset myValue = objURL.getVar("pageNum")/> On 9/13/06, Daniel Eben Elmore <[EMAIL PROTECTED]> wrote: Joe asked for an elegant solution. Why does everyone think that means condensed, bizarre, and hard to read? Is that your idea of "elegant" code? Would you like to maintain code that looks like this: listgetat(rereplace(test,"[(?|&)]*pageNum=(\d*)","#chr(10)#\1#chr(10)#","all "),2,chr(10)) My idea of elegance would involve having a URL object that receives a URL, parses it, and provides a method, getVar(), from which you can retrieve any URL variable. getVar("numPageID") -Daniel Elmore -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ] On Behalf Of Marlon Moyer Sent: Wednesday, September 13, 2006 7:44 PM To: Dallas/Fort Worth ColdFusion User Group Mailing List Subject: Re: [DFW CFUG] Brain Teaser <cfset pagenum = listgetat(rereplace(test,"[(?|&)]*pageNum=(\d*)","#chr(10)#\1#chr(10)#","all "),2,chr(10))> On 9/13/06, Joe Kelly <[EMAIL PROTECTED]> wrote: I want to see if someone can come up with a more elegant solution to this problem. Given: CGI.HTTP_REFERER will always have a URL variable, "numPageID=xxx" which is numeric and could be any size number. The HTTP_REFERER may or may not have other URL variables in any order, which could be alphanumeric or numeric The current template needs to pull the value of the "numPageID" URL variable out of the CGI.HTTP_REFERER I'll show my solution in another post so as not to spoil anyone's view on this problem, not saying that mine is best, of course! Thanks, Joe Kelly _______________________________________________ Reply to DFWCFUG: [email protected] Subscribe/Unsubscribe: http://lists1.safesecureweb.com/mailman/listinfo/list List Archives: http://www.mail-archive.com/list%40list.dfwcfug.org/ http://www.mail-archive.com/list%40dfwcfug.org/ DFWCFUG Sponsors: www.HostMySite.com www.teksystems.com/ -- Marlon _______________________________________________ Reply to DFWCFUG: [EMAIL PROTECTED] Subscribe/Unsubscribe: http://lists1.safesecureweb.com/mailman/listinfo/list List Archives: http://www.mail-archive.com/list%40list.dfwcfug.org/ http://www.mail-archive.com/list%40dfwcfug.org/ DFWCFUG Sponsors: www.HostMySite.com www.teksystems.com/ -- Marlon _______________________________________________ Reply to DFWCFUG: [email protected] Subscribe/Unsubscribe: http://lists1.safesecureweb.com/mailman/listinfo/list List Archives: http://www.mail-archive.com/list%40list.dfwcfug.org/ http://www.mail-archive.com/list%40dfwcfug.org/ DFWCFUG Sponsors: www.HostMySite.com www.teksystems.com/
