in reply to Perl & Regex
I think you are getting messed up because $( gets replaced with $REAL_GROUP_ID (ie $( ...)use strict; my $string = 'Price: $21343.355344'; my $searchString = qr|^Price: \$([0-9]+\.[0-9]+)|; if($string =~ /$searchString/) { print "Matches: $1\n"; } else { print "No Match: $`\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl & Regex
by Kzin (Acolyte) on Sep 08, 2004 at 23:33 UTC | |
| [reply] |
|
Re^2: Perl & Regex
by Anonymous Monk on Sep 09, 2004 at 09:57 UTC | |
Not always. There are some advantages to using qr. There are some disadvantages as well. 1) qr takes more memory than a string, which may matter if you have a lot of them. 2) in some cases, if you construct a large regex out of many small parts, qr is significantly slower than using strings - this is because in non-trivial interpolations, a qr-ed regex first gets stringified, which gives lots of extra parenthesis.
| [reply] [d/l] [select] |
|
Re^2: Perl & Regex
by Kzin (Acolyte) on Sep 08, 2004 at 23:32 UTC | |
| [reply] |
|
Re^2: Perl & Regex
by Kzin (Acolyte) on Sep 09, 2004 at 00:11 UTC | |
Ok here is the code, however I have changed the company to one *similar* to my own, just for example purposes. I dont claim affiliation to these guys disclaimer stuff goes here. I apologise ahead of time for lack of good meaningful comments and have to give credit to various sources from around the 'net for little tips here and there... like the qr thing. So the 'net owns this not me. hehe The file that it is reading from would be named "LensMart" or whatever you put in for company name. An example line would be... Acuvue###http://www.lensmart.com/scripts/ProductLens.asp/Pro dId=1/cur=1/cam=LM602###15.95 You could put many lines in that file, but I dont really want to go through that person's site and pull up all of their individual products. Dont forget to change the readpath to wherever you are going to put the file. This works best with linux because I have prepended the second file with . to hide it, as it is really just a temp file. I dont know what windows will do in this situation. Ok thats enough babbling, I shall now leave it to those who are more wise. | [reply] [d/l] |
by Kzin (Acolyte) on Sep 22, 2004 at 23:28 UTC | |
By Kzin | [reply] |