Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - Maximum length for a match

 
Thread Tools Search this Thread
Old 11-28-2006, 05:08 PM   #1
Default 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


Paul Johnston
  Reply With Quote
Old 11-28-2006, 06:21 PM   #2
Jim Gibson
 
Posts: n/a
Default Re: Maximum length for a match

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
Old 11-29-2006, 08:16 AM   #3
Paul Johnston
 
Posts: n/a
Default Re: Maximum length for a match

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 Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump