Maximum length for a match

Discussion in 'Perl' started by Paul Johnston, Nov 28, 2006.

  1. 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, Nov 28, 2006
    #1
    1. Advertising

  2. Paul Johnston

    Jim Gibson Guest

    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.
    Jim Gibson, Nov 28, 2006
    #2
    1. Advertising

  3. 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
    Paul Johnston, Nov 29, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacky Kwok
    Replies:
    2
    Views:
    3,530
    Mark1969
    Jun 24, 2005
  2. =?Utf-8?B?Y21heQ==?=
    Replies:
    8
    Views:
    30,786
    SilentSojourner
    Apr 2, 2012
  3. Chris Hayes
    Replies:
    8
    Views:
    9,344
    DDaanV
    Oct 21, 2010
  4. Replies:
    1
    Views:
    432
    Joe Seigh
    Dec 15, 2006
  5. phanhuyich
    Replies:
    4
    Views:
    254
Loading...

Share This Page