in reply to Re^2: Split a string at a given line number
in thread Split a string at a given line number

It seems you're running an old Perl. (?|) was introduced in the previous major version of Perl, 5.10, which was released 2.5 years ago.

You may consider upgrading to 5.10, or even 5.12.

Replies are listed 'Best First'.
Re^4: Split a string at a given line number
by danj35 (Sexton) on May 12, 2010 at 12:58 UTC
    Would be great, but I'm working on a company system here. Nothing can be upgraded without permissions and even with them 'free' software has a different definition for industry! Am trying to work with the one below, which works fine, but it removes the newlines from the string (which I might need to keep). Will keep battling with this!

      Tested with AS 5.8.9, should work (but untested) with pre-5.8:

      >perl -wMstrict -le "my $s = qq{line 1\nline 2\nline 3\nline 4\n}; my $l = 2; my @sra = $s =~ m{ (\A (?: [^\n]* \n){$l}) (.*) }xms; use Data::Dumper; print Dumper \@sra; " $VAR1 = [ 'line 1 line 2 ', 'line 3 line 4 ' ];
      If you do want to keep the newlines, I would use (untested):
      my @chunks = $string =~ /(?:[^\n]*\n){1,20}/g;