From: Blackstone, J. D. <jda...@ci...> - 2002-07-31 15:11:48
|
Another thing I meant to say about regexes is I think it would be really cool if we could drop -re altogether. To my mind it seems like the method should use ref to see if you've passed a qr// regex or a plain scalar. Of course, my mind doesn't work like anyone else's, and it would break backward compatibility. However, this seems to be more in keeping with Perl 6's newfound "A regex is not really a string" philosophy. qr// was a great piece of syntax, and I'd like to see it be a more first-class member of the language with some modules. jdb |
From: Blackstone, J. D. <jda...@ci...> - 2002-08-05 13:57:52
|
> Btw, just noticed this. Did you mean: > > $exp->expect($timeout, > [ "regexp", \&callback ], > ^^^^^^^^ > > "substring"? If we allow for a Regex to be passed, DWIM > would seem > to indicate that a non-Regex would be a substring. > Gee, come to think of it, if we allow for Regex objects to be > passed, we probably don't need the ugly tomfoolery for > multiline matching, etc. And that's why I think precompiled regexes are my favorite new feature in all of Perl that's happened since 5.005. Probably favorite new feature since XS, to be honest. It's amazing what you can do with precompiled regexes. Especially with ref $regex. (Sounds like we lit a fire for Roland. :) ) jdb |
From: Blackstone, J. D. <jda...@ci...> - 2002-08-05 13:59:08
|
> -----Original Message----- > From: Roland Giersig [mailto:RGi...@cp...] > Sent: Sunday, August 04, 2002 5:00 AM > To: Blackstone, J. David > Cc: exp...@li... > Subject: RE: [Expectperl-discuss] quotes around $scalar > > > Quoting "Blackstone, J. David" <jda...@ci...>: > > > Another thing I meant to say about regexes is I think it would be > > really cool if we could drop -re altogether. To my mind it > seems like the > > method should use ref to see if you've passed a qr// regex > or a plain > > scalar. Of course, my mind doesn't work like anyone else's, and it > would break > > backward compatibility. > > Right, and that's why it's not gonna happen. Please note > that with the > new syntax with callbacks it's already the default: > > $exp->expect($timeout, > [ "regexp", \&callback ], > [ qr/regexp/, \&callback ],); > > And this is the much more powerful syntax, so I personally > consider the > old syntax (where you have to test which regexp index has matched) > somewhat obsolete and only a beginners drug to get them hooked until > they realize the full power of callbacks... :-) Ah, that makes sense. I only use the older syntax for very simple statements, e.g.: $x->expect($t, "string"); that is, when I want to do the equivalent to TCL/Expect's expect string Of course, with ref $regex, there's no telling what you can do. :) jdb |
From: Blackstone, J. D. <jda...@ci...> - 2002-08-05 14:05:43
|
> -----Original Message----- > From: Roland Giersig [mailto:RGi...@cp...] > Sent: Sunday, August 04, 2002 3:50 PM > To: Austin Schutz > Cc: exp...@li... > Subject: Re: [Expectperl-discuss] quotes around $scalar > > > >>Hmm, I offhand don't know a means to find out if a given > scalar already > >>contains a precompiled regexp. If such a check is > available I'd surely > >>implement it to make expect() even more DWIMmish in that > regard, making > >>sure that a precompiled regexp wouldn't be handled with a > substr match... > >> > >>Anybody got an idea? > >> > >> > > > > $foo = qr /stuff/; > > print ref($foo); > > > > prints "Regexp". Is that what you mean? > > > *smack* > > Ugh, yes, and I was looking into Scalar::Util and thought > about digging > into perl internas and write some .xs code... > > Looks like it's time to add some more DWIM to Expect... I just remembered something significant, something you're not going to want to hear. I think the return value of ref for a precompiled regex changed at some point for consistency. Hmmm... digging through old perldeltas ... I don't see it. Maybe I just dreamed it. Or maybe they were just talking about it. At any rate, a test with 5.00502 seems to yield the same results as 5.8.0, so never mind. (But be wary in case they jump up and change it some day.) jdb |
From: Austin S. <te...@of...> - 2002-07-31 17:12:22
|
On Wed, Jul 31, 2002 at 10:11:42AM -0500, Blackstone, J. David wrote: > Another thing I meant to say about regexes is I think it would be really > cool if we could drop -re altogether. I don't see why you'd want to drop it. It'd be a slight bit of cruft, but I can't see it breaking anything. -re is also familiar for folks migrating from Tcl. > To my mind it seems like the method > should use ref to see if you've passed a qr// regex or a plain scalar. Of > course, my mind doesn't work like anyone else's, and it would break backward > compatibility. > It won't if you leave -re in and allow folks to use either method. Definitely the qr// method seems more perlish. Austin |
From: Roland G. <RGi...@cp...> - 2002-08-04 10:01:10
|
Quoting "Blackstone, J. David" <jda...@ci...>: > Another thing I meant to say about regexes is I think it would be > really cool if we could drop -re altogether. To my mind it seems like the > method should use ref to see if you've passed a qr// regex or a plain > scalar. Of course, my mind doesn't work like anyone else's, and it would break > backward compatibility. Right, and that's why it's not gonna happen. Please note that with the new syntax with callbacks it's already the default: $exp->expect($timeout, [ "regexp", \&callback ], [ qr/regexp/, \&callback ],); And this is the much more powerful syntax, so I personally consider the old syntax (where you have to test which regexp index has matched) somewhat obsolete and only a beginners drug to get them hooked until they realize the full power of callbacks... :-) > However, this seems to be more in keeping with Perl 6's newfound "A > regex is not really a string" philosophy. qr// was a great piece of > syntax, and I'd like to see it be a more first-class member of the language with > some modules. Hmm, I offhand don't know a means to find out if a given scalar already contains a precompiled regexp. If such a check is available I'd surely implement it to make expect() even more DWIMmish in that regard, making sure that a precompiled regexp wouldn't be handled with a substr match... Anybody got an idea? Roland -- RGi...@cp... |
From: Austin S. <te...@of...> - 2002-08-04 19:45:57
|
> And this is the much more powerful syntax, so I personally consider the > old syntax (where you have to test which regexp index has matched) > somewhat obsolete and only a beginners drug to get them hooked until > they realize the full power of callbacks... :-) > It's definitely enables more of the tcl-ish syntax. > > However, this seems to be more in keeping with Perl 6's newfound "A > > regex is not really a string" philosophy. qr// was a great piece of > > syntax, and I'd like to see it be a more first-class member of the > language with > > some modules. > > Hmm, I offhand don't know a means to find out if a given scalar already > contains a precompiled regexp. If such a check is available I'd surely > implement it to make expect() even more DWIMmish in that regard, making > sure that a precompiled regexp wouldn't be handled with a substr match... > > Anybody got an idea? > $foo = qr /stuff/; print ref($foo); prints "Regexp". Is that what you mean? Austin |
From: Roland G. <RGi...@cp...> - 2002-08-04 20:51:42
|
>>Hmm, I offhand don't know a means to find out if a given scalar already >>contains a precompiled regexp. If such a check is available I'd surely >>implement it to make expect() even more DWIMmish in that regard, making >>sure that a precompiled regexp wouldn't be handled with a substr match... >> >>Anybody got an idea? >> >> > > $foo = qr /stuff/; > print ref($foo); > > prints "Regexp". Is that what you mean? *smack* Ugh, yes, and I was looking into Scalar::Util and thought about digging into perl internas and write some .xs code... Looks like it's time to add some more DWIM to Expect... Roland -- RGi...@cp... |
From: Austin S. <te...@of...> - 2002-08-04 21:14:11
|
On Sun, Aug 04, 2002 at 12:00:25PM +0200, Roland Giersig wrote: > Quoting "Blackstone, J. David" <jda...@ci...>: > > > Another thing I meant to say about regexes is I think it would be > > really cool if we could drop -re altogether. To my mind it seems like the > > method should use ref to see if you've passed a qr// regex or a plain > > scalar. Of course, my mind doesn't work like anyone else's, and it > would break > > backward compatibility. > > Right, and that's why it's not gonna happen. Please note that with the > new syntax with callbacks it's already the default: > > $exp->expect($timeout, > [ "regexp", \&callback ], > [ qr/regexp/, \&callback ],); > Btw, just noticed this. Did you mean: $exp->expect($timeout, [ "regexp", \&callback ], ^^^^^^^^ "substring"? If we allow for a Regex to be passed, DWIM would seem to indicate that a non-Regex would be a substring. Gee, come to think of it, if we allow for Regex objects to be passed, we probably don't need the ugly tomfoolery for multiline matching, etc. Austin |