RE: Using reReplace Backreference as StructKey or Argument

2007-11-16 Thread Ben Nadel
Jon,

My recommendation AGAINST using REFind() in a loop is that I feel like
it has to keep revaluating the string. The Java Pattern matcher which is
what powers the REMatchGroups() UDF is designed to iterate over pattern
matches and as such I assume that it is really good at it. Plus, I think
that you will find that dealing with the Len[] and Pos[] arrays is going
to look less than elegant. I don't think there is anyone who has even
enjoyed dealing with them :)

This is all theory though, I have never checked the performance. 


..
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
 
Need ColdFusion Help?
www.bennadel.com/ask-ben/

-Original Message-
From: Jon Clausen [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 15, 2007 8:17 PM
To: CF-Talk
Subject: Re: Using reReplace Backreference as StructKey or Argument

Ben,

Thanks for the reply.  I had sent a response to Ben's reply earlier
today, but I guess it didn't go through.

I figured the order of execution was the issue.  I was hoping for a way
to trick the execution order and tried writing the function call in a
bunch of different ways other than the example I provided, but no  
dice.   Ben posted a nice response, though looping with reFind() does  
the job for now.

Thanks again,

Jon


On Nov 15, 2007, at 10:02 AM, Ben Doom wrote:

 Sorry, you can't do that.  Here's why:

 Coldfusion hands strings off to the regex engine.  CF allows you to 
 used functions, variables, etc. in the string, but it executes them
 *before*
 the regex runs.  So, in your first code sample, it's trying to find 
 the literal key \1 in appSettings, and then passing the result as the 
 replace value.

 --Ben Doom

 Jon Clausen wrote:
 I'm sure it's something simple that I'm missing, but I want to use a 
 regex backreference as the struct key (i.e. - struct[key])  or as 
 an argument (i.e. - function(argument) ) but I've failed in all my 
 attempts so far.

  For now I've written the code out using a loop with reFind(), 
 returning subexpressions, mid(), etc. but it seems to me there should

 be a way to do this using reReplace() and pass the backreference as 
 an argument/key.  Usage of evaluate() would probably be a 
 deal-breaker since it would be less expensive to perform the loop.

 Here's examples of what i'm trying to do:

 !--- Trying to use backref passed as struct key --- cfset pageOut 
 = reReplace(pageContent,%show:([a-zA-Z0-9_]+)
 %,appSettings[\1],ALL)/

 !--- Trying to use backref passed as argument --- cfset pageOut = 
 reReplace(pageContent,%getModule:([a-zA-Z0-9_]+)
 %,controller.getModule(\1),ALL)/

 Thoughts?

 Jon




 



~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293454
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Using reReplace Backreference as StructKey or Argument

2007-11-16 Thread Jon Clausen
Ben,

Agreed, the Len/Pos array loops are ugly and a pain to deal with.   
Hence my attempts to bypass all of that by finding a way to pass the  
backreference directly in reReplace... :-)

Got around to running timers comparing reFind and your reMatchGroups  
function against each other.The first set ran both options  
together in the same function and produced significantly faster  
results for rematchGroups.   The next 5 sets were done in a loop with  
both functions side by side.reMatchGroups came out ahead again on  
the average.

When I ran each timer by itself,   revmoving the other from the  
function, reFind() came out faster on both sets (plus a few more  
attempts I didn't capture in these results).

While not exactly scientific, the timer results are included below  
(tab separated - sorry for the formatting in plain text):

Timer Run   Using ReFind(ms)Using RematchGroups(ms)
Base Run52762879
Loop 1  42413434
Loop 2  41093284
Loop3   34403080
Loop 4  32902894
Loop 5  29943209
Solo Run 1  39754675
Solo Run 2  35013556
Average 3853.25 3376.375
Difference  -14.12% 12.38%
Machine Info:  CF8 | 2GHz Macbook Pro 2GB RAM

  Based on the results, It seems that reMatchGroups has a speed  
advantage with a high load, but reFind seems to perform better in a  
single request.  There were no database calls in the timers to cloud  
the results.

Interesting stuff!

Jon

On Nov 16, 2007, at 8:42 AM, Ben Nadel wrote:

 Jon,

 My recommendation AGAINST using REFind() in a loop is that I feel like
 it has to keep revaluating the string. The Java Pattern matcher  
 which is
 what powers the REMatchGroups() UDF is designed to iterate over  
 pattern
 matches and as such I assume that it is really good at it. Plus, I  
 think
 that you will find that dealing with the Len[] and Pos[] arrays is  
 going
 to look less than elegant. I don't think there is anyone who has even
 enjoyed dealing with them :)

 This is all theory though, I have never checked the performance.


 ..
 Ben Nadel
 Certified Advanced ColdFusion MX7 Developer
 www.bennadel.com

 Need ColdFusion Help?
 www.bennadel.com/ask-ben/

 -Original Message-
 From: Jon Clausen [mailto:[EMAIL PROTECTED]
 Sent: Thursday, November 15, 2007 8:17 PM
 To: CF-Talk
 Subject: Re: Using reReplace Backreference as StructKey or Argument

 Ben,

 Thanks for the reply.  I had sent a response to Ben's reply earlier
 today, but I guess it didn't go through.

 I figured the order of execution was the issue.  I was hoping for a  
 way
 to trick the execution order and tried writing the function call  
 in a
 bunch of different ways other than the example I provided, but no
 dice.   Ben posted a nice response, though looping with reFind() does
 the job for now.

 Thanks again,

 Jon


 On Nov 15, 2007, at 10:02 AM, Ben Doom wrote:

 Sorry, you can't do that.  Here's why:

 Coldfusion hands strings off to the regex engine.  CF allows you to
 used functions, variables, etc. in the string, but it executes them
 *before*
 the regex runs.  So, in your first code sample, it's trying to find
 the literal key \1 in appSettings, and then passing the result as the
 replace value.

 --Ben Doom

 Jon Clausen wrote:
 I'm sure it's something simple that I'm missing, but I want to use a
 regex backreference as the struct key (i.e. - struct[key])  or as
 an argument (i.e. - function(argument) ) but I've failed in all my
 attempts so far.

 For now I've written the code out using a loop with reFind(),
 returning subexpressions, mid(), etc. but it seems to me there  
 should

 be a way to do this using reReplace() and pass the backreference as
 an argument/key.  Usage of evaluate() would probably be a
 deal-breaker since it would be less expensive to perform the loop.

 Here's examples of what i'm trying to do:

 !--- Trying to use backref passed as struct key --- cfset pageOut
 = reReplace(pageContent,%show:([a-zA-Z0-9_]+)
 %,appSettings[\1],ALL)/

 !--- Trying to use backref passed as argument --- cfset pageOut =
 reReplace(pageContent,%getModule:([a-zA-Z0-9_]+)
 %,controller.getModule(\1),ALL)/

 Thoughts?

 Jon








 

~|
Download the latest ColdFusion 8 utilities including Report Builder,
plug-ins for Eclipse and Dreamweaver updates.
http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293474
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


RE: Using reReplace Backreference as StructKey or Argument

2007-11-16 Thread Ben Nadel
Jon,

That makes sense I suppose. The REMatchGroups() has to create some Java
objects which must have some overhead. Plus it is creating arrays and
structs and some grunt work. This might come out faster on big things,
but for smaller things, the simplier approach might prevail.

Thanks for the feedback. 

..
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
 
Need ColdFusion Help?
www.bennadel.com/ask-ben/

-Original Message-
From: Jon Clausen [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 16, 2007 11:44 AM
To: CF-Talk
Subject: Re: Using reReplace Backreference as StructKey or Argument

Ben,

Agreed, the Len/Pos array loops are ugly and a pain to deal with.   
Hence my attempts to bypass all of that by finding a way to pass the
backreference directly in reReplace... :-)

Got around to running timers comparing reFind and your reMatchGroups  
function against each other.The first set ran both options  
together in the same function and produced significantly faster  
results for rematchGroups.   The next 5 sets were done in a loop with  
both functions side by side.reMatchGroups came out ahead again on  
the average.

When I ran each timer by itself,   revmoving the other from the  
function, reFind() came out faster on both sets (plus a few more
attempts I didn't capture in these results).

While not exactly scientific, the timer results are included below (tab
separated - sorry for the formatting in plain text):

Timer Run   Using ReFind(ms)Using RematchGroups(ms)
Base Run52762879
Loop 1  42413434
Loop 2  41093284
Loop3   34403080
Loop 4  32902894
Loop 5  29943209
Solo Run 1  39754675
Solo Run 2  35013556
Average 3853.25 3376.375
Difference  -14.12% 12.38%
Machine Info:  CF8 | 2GHz Macbook Pro 2GB RAM

  Based on the results, It seems that reMatchGroups has a speed
advantage with a high load, but reFind seems to perform better in a
single request.  There were no database calls in the timers to cloud the
results.

Interesting stuff!

Jon

~|
Check out the new features and enhancements in the
latest product release - download the What's New PDF now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293479
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


RE: Using reReplace Backreference as StructKey or Argument

2007-11-15 Thread Ben Nadel
Jon,

You cannot do that because the arguments of the REReplace() method are
eveluated at the initial method execution time. Back references within a
string are fine because they are evaluated within the inner working of
the RERepalce() method. However, you cannot use them as part of another
structure (ie, struct key) because that argument will be evaluated
before the reg-ex replace actually even runs. 

What you need to a algorithm that doesn't really do a replace but
actually returns a structure of reg-ex groups. I threw this together in
hopes that it might help:

http://www.bennadel.com/blog/1040-REMatchGroups-ColdFusion-User-Defined-
Function.htm
Or- http://bennadel.com/index.cfm?dax=blog:1040.view


..
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
 
Need ColdFusion Help?
www.bennadel.com/ask-ben/

-Original Message-
From: Jon Clausen [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 14, 2007 8:40 PM
To: CF-Talk
Subject: Using reReplace Backreference as StructKey or Argument

I'm sure it's something simple that I'm missing, but I want to use a
regex backreference as the struct key (i.e. - struct[key])  or as an
argument (i.e. - function(argument) ) but I've failed in all my
attempts so far.

  For now I've written the code out using a loop with reFind(),
returning subexpressions, mid(), etc. but it seems to me there should be
a way to do this using reReplace() and pass the backreference as an
argument/key.  Usage of evaluate() would probably be a deal-breaker
since it would be less expensive to perform the loop.

Here's examples of what i'm trying to do:

!--- Trying to use backref passed as struct key --- cfset pageOut =
reReplace(pageContent,%show:([a-zA-Z0-9_]+)
%,appSettings[\1],ALL)/

!--- Trying to use backref passed as argument --- cfset pageOut =
reReplace(pageContent,%getModule:([a-zA-Z0-9_]+)
%,controller.getModule(\1),ALL)/

Thoughts?

Jon




~|
ColdFusion 8 - Build next generation apps
today, with easy PDF and Ajax features - download now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293397
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Using reReplace Backreference as StructKey or Argument

2007-11-15 Thread Ben Doom
Sorry, you can't do that.  Here's why:

Coldfusion hands strings off to the regex engine.  CF allows you to used 
functions, variables, etc. in the string, but it executes them *before* 
the regex runs.  So, in your first code sample, it's trying to find the 
literal key \1 in appSettings, and then passing the result as the 
replace value.

--Ben Doom

Jon Clausen wrote:
 I'm sure it's something simple that I'm missing, but I want to use a  
 regex backreference as the struct key (i.e. - struct[key])  or as an  
 argument (i.e. - function(argument) ) but I've failed in all my  
 attempts so far.
 
   For now I've written the code out using a loop with reFind(),  
 returning subexpressions, mid(), etc. but it seems to me there should  
 be a way to do this using reReplace() and pass the backreference as an  
 argument/key.  Usage of evaluate() would probably be a deal-breaker  
 since it would be less expensive to perform the loop.
 
 Here's examples of what i'm trying to do:
 
 !--- Trying to use backref passed as struct key ---
 cfset pageOut = reReplace(pageContent,%show:([a-zA-Z0-9_]+) 
 %,appSettings[\1],ALL)/
 
 !--- Trying to use backref passed as argument ---
 cfset pageOut = reReplace(pageContent,%getModule:([a-zA-Z0-9_]+) 
 %,controller.getModule(\1),ALL)/
 
 Thoughts?
 
 Jon
 
 
 

~|
Get involved in the latest ColdFusion discussions, product
development sharing, and articles on the Adobe Labs wiki.
http://labs/adobe.com/wiki/index.php/ColdFusion_8

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293375
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Using reReplace Backreference as StructKey or Argument

2007-11-15 Thread Jon Clausen
Ben,

Thanks!  As always, you rock!   I had kind of figured that the method  
execution order was the issue, but was hoping to find a workaround to  
trick the excution so that the regex backref was captured before the  
method was called.

Very nice code and potentially very useful!   I'm not entirely sure  
that, in my situation, it's going to be faster than using a loop with  
reFind() as I have currently, though I'm going to check it out with  
some timers later today.  I'll let you know the results.

What you've written, though could be tremendously useful for parsing  
the contents of a file and turning into workable data for reuse.  In  
my case I'm simply replacing the user provided  shorthand tokens so  
there's no need to retain the information after the token has been  
replaced.

Nice work!

Jon


On Nov 15, 2007, at 11:35 AM, Ben Nadel wrote:

 Jon,

 You cannot do that because the arguments of the REReplace() method are
 eveluated at the initial method execution time. Back references  
 within a
 string are fine because they are evaluated within the inner working of
 the RERepalce() method. However, you cannot use them as part of  
 another
 structure (ie, struct key) because that argument will be evaluated
 before the reg-ex replace actually even runs.

 What you need to a algorithm that doesn't really do a replace but
 actually returns a structure of reg-ex groups. I threw this together  
 in
 hopes that it might help:

 http://www.bennadel.com/blog/1040-REMatchGroups-ColdFusion-User-Defined-
 Function.htm
 Or- http://bennadel.com/index.cfm?dax=blog:1040.view


 ..
 Ben Nadel
 Certified Advanced ColdFusion MX7 Developer
 www.bennadel.com

 Need ColdFusion Help?
 www.bennadel.com/ask-ben/

 -Original Message-
 From: Jon Clausen [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, November 14, 2007 8:40 PM
 To: CF-Talk
 Subject: Using reReplace Backreference as StructKey or Argument

 I'm sure it's something simple that I'm missing, but I want to use a
 regex backreference as the struct key (i.e. - struct[key])  or as an
 argument (i.e. - function(argument) ) but I've failed in all my
 attempts so far.

  For now I've written the code out using a loop with reFind(),
 returning subexpressions, mid(), etc. but it seems to me there  
 should be
 a way to do this using reReplace() and pass the backreference as an
 argument/key.  Usage of evaluate() would probably be a deal-breaker
 since it would be less expensive to perform the loop.

 Here's examples of what i'm trying to do:

 !--- Trying to use backref passed as struct key --- cfset pageOut =
 reReplace(pageContent,%show:([a-zA-Z0-9_]+)
 %,appSettings[\1],ALL)/

 !--- Trying to use backref passed as argument --- cfset pageOut =
 reReplace(pageContent,%getModule:([a-zA-Z0-9_]+)
 %,controller.getModule(\1),ALL)/

 Thoughts?

 Jon




 

~|
Create robust enterprise, web RIAs.
Upgrade to ColdFusion 8 and integrate with Adobe Flex
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293409
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: Using reReplace Backreference as StructKey or Argument

2007-11-15 Thread Jon Clausen
Ben,

Thanks for the reply.  I had sent a response to Ben's reply earlier  
today, but I guess it didn't go through.

I figured the order of execution was the issue.  I was hoping for a  
way to trick the execution order and tried writing the function call  
in a bunch of different ways other than the example I provided, but no  
dice.   Ben posted a nice response, though looping with reFind() does  
the job for now.

Thanks again,

Jon


On Nov 15, 2007, at 10:02 AM, Ben Doom wrote:

 Sorry, you can't do that.  Here's why:

 Coldfusion hands strings off to the regex engine.  CF allows you to  
 used
 functions, variables, etc. in the string, but it executes them  
 *before*
 the regex runs.  So, in your first code sample, it's trying to find  
 the
 literal key \1 in appSettings, and then passing the result as the
 replace value.

 --Ben Doom

 Jon Clausen wrote:
 I'm sure it's something simple that I'm missing, but I want to use a
 regex backreference as the struct key (i.e. - struct[key])  or as  
 an
 argument (i.e. - function(argument) ) but I've failed in all my
 attempts so far.

  For now I've written the code out using a loop with reFind(),
 returning subexpressions, mid(), etc. but it seems to me there should
 be a way to do this using reReplace() and pass the backreference as  
 an
 argument/key.  Usage of evaluate() would probably be a deal-breaker
 since it would be less expensive to perform the loop.

 Here's examples of what i'm trying to do:

 !--- Trying to use backref passed as struct key ---
 cfset pageOut = reReplace(pageContent,%show:([a-zA-Z0-9_]+)
 %,appSettings[\1],ALL)/

 !--- Trying to use backref passed as argument ---
 cfset pageOut = reReplace(pageContent,%getModule:([a-zA-Z0-9_]+)
 %,controller.getModule(\1),ALL)/

 Thoughts?

 Jon




 

~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293437
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4