in reply to Regex to array
If you trust that your data will be well-formed, you can simply match what you want to keep instead of splitting the string:
my %values = ($string =~ /(SECTION \d+)\s+(.*?)/sg);
That idea doesn't work :-/ :
my $string = <<STR; SECTION 1 This is section 1 SECTION 2 This is section 2 STR use Data::Dumper; my %values = ($string =~ /(SECTION \d+)\s+(.*?)/sg); print Dumper \%values;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to array
by Eily (Monsignor) on Jan 09, 2018 at 13:40 UTC | |
by kepler (Scribe) on Jan 11, 2018 at 18:05 UTC |