Maximum length for a match

P

Paul Johnston

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
 
J

Jim Gibson

Paul Johnston said:
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.
 
P

Paul Johnston

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top