Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Maximum length for a match (http://www.velocityreviews.com/forums/t376812-maximum-length-for-a-match.html)

 Paul Johnston 11-28-2006 05:08 PM

Maximum length for a match

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

 Jim Gibson 11-28-2006 06:21 PM

Re: Maximum length for a match

In article <70rom2lojv0gj1mgclvar242bb7q3l4ppm@4ax.com>, Paul Johnston
<paul.johnston@manchester.ac.uk> 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.

 Paul Johnston 11-29-2006 08:16 AM

Re: Maximum length for a match

On Tue, 28 Nov 2006 10:21:50 -0800, Jim Gibson
<jgibson@mail.arc.nasa.gov> wrote:

>In article <70rom2lojv0gj1mgclvar242bb7q3l4ppm@4ax.com>, Paul Johnston
><paul.johnston@manchester.ac.uk> 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

 All times are GMT. The time now is 12:29 PM.