Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Maximum length for a match

Reply
Thread Tools

Maximum length for a match

 
 
Paul Johnston
Guest
Posts: n/a
 
      11-28-2006
I know this may sound silly but given something like

if ($_ =~m/(one)|(two)|(three)/)

Is there a maximum length on the size of the item between "/" and" /"
?
Just curious as regards showing bad programming techniques.

TIA Paul
 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      11-28-2006
In article <>, Paul Johnston
<> wrote:

> I know this may sound silly but given something like
>
> if ($_ =~m/(one)|(two)|(three)/)
>
> Is there a maximum length on the size of the item between "/" and" /"
> ?
> Just curious as regards showing bad programming techniques.


There is no inherent limit. You are limited by your available memory
for Perl scalars. You can test this easily:

#!/usr/local/bin/perl

use strict;
use warnings;

my $re;
for my $x ( 'aaaa' .. 'zzzz' ) {
$re .= "($x)|";
}
my $s = 'XXXXX';
$re .= "($s)";
print "Length of RE = ", length($re), "\n";
if( $s =~ m/$re/ ) {
print "Match: $&\n";
}

__OUTPUT__

Length of RE = 3198839
Match: XXXXX


FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 
Reply With Quote
 
 
 
 
Paul Johnston
Guest
Posts: n/a
 
      11-29-2006
On Tue, 28 Nov 2006 10:21:50 -0800, Jim Gibson
<> wrote:

>In article <>, Paul Johnston
><> wrote:
>
>> I know this may sound silly but given something like
>>
>> if ($_ =~m/(one)|(two)|(three)/)
>>
>> Is there a maximum length on the size of the item between "/" and" /"
>> ?
>> Just curious as regards showing bad programming techniques.

>
>There is no inherent limit. You are limited by your available memory
>for Perl scalars. You can test this easily:
>
>#!/usr/local/bin/perl
>
>use strict;
>use warnings;
>
>my $re;
>for my $x ( 'aaaa' .. 'zzzz' ) {
> $re .= "($x)|";
>}
>my $s = 'XXXXX';
>$re .= "($s)";
>print "Length of RE = ", length($re), "\n";
>if( $s =~ m/$re/ ) {
> print "Match: $&\n";
>}
>
>__OUTPUT__
>
>Length of RE = 3198839
>Match: XXXXX
>
>
>FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.


Many Thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is there any FAST ALGORITHM about Forward Maximum Match of string? hn.ft.pris@gmail.com C++ 1 12-15-2006 01:42 PM
Creating the maximum number of menus and maximum number of stills rossco DVD Video 2 11-24-2005 09:33 PM
Application_Error and Maximum request length exceeded Jacky Kwok ASP .Net 2 06-24-2005 08:24 AM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net Web Controls 2 07-16-2004 05:14 PM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net 2 07-02-2004 10:35 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57