Help for this page

Select Code to Download


  1. or download this
    @list = split /(?=PATTERN)/;
    
  2. or download this
    my $pat = qr/^[ \t]*[^\s:]+:[ \t]*$/m;  # allow leading/trailing ws
    my $pat = qr/^[^\s:]+:/m;
    
    $_ = slurp_file;
    my @stanzas = split /(?=$pat)/o;
    
  3. or download this
    @list = /( .*? PATTERN | .+ )/gsx;
    
  4. or download this
    my $pat = qr/(?:^[ \t]*\n)+(?:[ \t]+\z)?/m;
    
    $_ = slurp_file;
    my @list = /( .*? $pat | .+ )/ogsx;
    
  5. or download this
    my @list = split /^\s*(?:\n|\z)/m;
    shift @list if @list && $list[0] eq "";  # remove empty first element
    
  6. or download this
    my $delim = qr/^[ \t]*SOMETHING[ \t]*$/m;
    my $pat   = qr/$delim(?:\n[ \t]*)*(?:\n|\z)/o;
    
  7. or download this
    # Partition a string into paragraphs based on a 
    # pattern which matches the beginning of a paragraph.
    ...
       }
       return $str =~ /(.*?(?:$pat)|.+)/gs;
    }