Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 28th, 2006, 04:45 PM
Paul Johnston
Guest
 
Posts: n/a
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
  #2  
Old November 28th, 2006, 06:05 PM
Jim Gibson
Guest
 
Posts: n/a
Default Re: Maximum length for a match

In article <70rom2lojv0gj1mgclvar242bb7q3l4ppm@4ax.com>, Paul Johnston
<paul.johnston@manchester.ac.ukwrote:
Quote:
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.
  #3  
Old November 29th, 2006, 07:55 AM
Paul Johnston
Guest
 
Posts: n/a
Default Re: Maximum length for a match

On Tue, 28 Nov 2006 10:21:50 -0800, Jim Gibson
<jgibson@mail.arc.nasa.govwrote:
Quote:
>In article <70rom2lojv0gj1mgclvar242bb7q3l4ppm@4ax.com>, Paul Johnston
><paul.johnston@manchester.ac.ukwrote:
>
Quote:
>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
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles